1 # -*- coding: utf-8 -*-
2 # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django.conf import settings
6 from django.contrib import admin
7 from django.utils.translation import ugettext_lazy as _
8 from migdal.models import Category, Entry, Attachment
9 from migdal import app_settings
10 from migdal.helpers import translated_fields
13 class AttachmentInline(admin.TabularInline):
15 readonly_fields = ['url']
18 class EntryAdmin(admin.ModelAdmin):
19 date_hierarchy = 'date'
21 (None, {'fields': (('type', 'promo'), 'author', 'author_email', 'image')}),
24 ('published_%s' % lc),
30 for lc, ln in app_settings.OBLIGATORY_LANGUAGES
33 ('needed_%s' % lc, 'published_%s' % lc),
39 for lc, ln in app_settings.OPTIONAL_LANGUAGES
41 (_('Categories'), {'fields': ('categories',)}),
43 prepopulated_fields = dict([
44 ("slug_%s" % lang_code, ("title_%s" % lang_code,))
45 for lang_code, lang_name in settings.LANGUAGES
48 list_display = translated_fields(('title',), app_settings.OBLIGATORY_LANGUAGES
49 ) + ('type', 'date', 'author', 'promo'
50 ) + translated_fields(('published',)
51 ) + translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES)
52 list_filter = ('type', 'promo') + translated_fields(('published',)
53 ) + translated_fields(('needed',), app_settings.OPTIONAL_LANGUAGES)
54 inlines = (AttachmentInline,)
57 class CategoryAdmin(admin.ModelAdmin):
58 list_display = translated_fields(('title', 'slug')) + ('taxonomy',)
59 prepopulated_fields = dict([
60 ("slug_%s" % lang_code, ("title_%s" % lang_code,))
61 for lang_code, lang_name in settings.LANGUAGES
65 admin.site.register(Entry, EntryAdmin)
66 admin.site.register(Category, CategoryAdmin)