X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/fc7a60feb9496c250cd1e8ca3db8c74267790047..113e9584a18733aabe8a2ec20862eb6f5ed4b62d:/apps/explorer/admin.py diff --git a/apps/explorer/admin.py b/apps/explorer/admin.py index e4389e0c..c84a5d93 100644 --- a/apps/explorer/admin.py +++ b/apps/explorer/admin.py @@ -1,8 +1,30 @@ from django.contrib import admin -from django.utils.translation import ugettext_lazy as _ +from django import forms +import os + +from django.conf import settings import explorer.models admin.site.register(explorer.models.EditorSettings) -admin.site.register(explorer.models.Book) -admin.site.register(explorer.models.EditorPanel) \ No newline at end of file +admin.site.register(explorer.models.EditorPanel) + + +class GalleryAdminForm(forms.ModelForm): + subpath = forms.ChoiceField(choices=()) + + def __init__(self, *args, **kwargs): + super(GalleryAdminForm, self).__init__(*args, **kwargs) + self.fields['subpath'].choices = [(settings.IMAGE_DIR + '/' + x, x) for x in os.listdir(settings.MEDIA_ROOT + settings.IMAGE_DIR)] + + class Meta: + mode = explorer.models.GalleryForDocument + fields = ('document', 'subpath',) + + +class GalleryAdmin(admin.ModelAdmin): + form = GalleryAdminForm + list_display = ('document', 'subpath',) + search_fields = ('document', 'subpath',) + +admin.site.register(explorer.models.GalleryForDocument, GalleryAdmin) \ No newline at end of file