From 54d7b5abd1eddc6f22f8d3df75334a54a1420485 Mon Sep 17 00:00:00 2001 From: zuber Date: Fri, 6 Nov 2009 00:14:15 +0100 Subject: [PATCH] =?utf8?q?=C5=81atwiejsze=20wybieranie=20galerii=20dla=20d?= =?utf8?q?okument=C3=B3w=20w=20interfejsie=20administracyjnym.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- apps/explorer/admin.py | 25 ++++++++++++++++++++++++- apps/explorer/models.py | 13 +++++++------ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/apps/explorer/admin.py b/apps/explorer/admin.py index 10c3e79a..097514a9 100644 --- a/apps/explorer/admin.py +++ b/apps/explorer/admin.py @@ -1,7 +1,30 @@ from django.contrib import admin +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.EditorPanel) -admin.site.register(explorer.models.GalleryForDocument) \ No newline at end of file + + +class GalleryAdminForm(forms.ModelForm): + subpath = forms.ChoiceField(choices=()) + + def __init__(self, *args, **kwargs): + super(GalleryAdminForm, self).__init__(*args, **kwargs) + self.fields['subpath'].choices = [(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 diff --git a/apps/explorer/models.py b/apps/explorer/models.py index 73e9063a..e104cda6 100644 --- a/apps/explorer/models.py +++ b/apps/explorer/models.py @@ -58,13 +58,14 @@ class EditorPanel(models.Model): # Yes, this is intentionally unnormalized ! class GalleryForDocument(models.Model): - name = models.CharField(max_length=100) - - # directory containing scans under MEDIA_ROOT/ - subpath = models.CharField(max_length=255) + name = models.CharField(max_length=100, blank=True) # document associated with the gallery - document = models.CharField(max_length=255) + document = models.CharField(max_length=255, unique=True) + + # directory containing scans under MEDIA_ROOT/ + subpath = models.CharField(max_length=255) def __unicode__(self): - return u"%s:%s" % (self.subpath, self.document) \ No newline at end of file + return u"%s:%s" % (self.subpath, self.document) + -- 2.20.1