diff options
author | luxagraf <sng@luxagraf.net> | 2017-09-06 19:28:47 -0600 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2017-09-06 19:28:47 -0600 |
commit | ef2fbc67a923e4d39f0497943c11dc1eaeb74f5d (patch) | |
tree | 49a92961204446c11687296f2ca52fb815c47f50 /app/photos/forms.py | |
parent | 6eeb020f226110a42a7d3d68b04244dbc03ecfde (diff) |
updated bird and jrnl admins to make maps and photos better
Diffstat (limited to 'app/photos/forms.py')
-rw-r--r-- | app/photos/forms.py | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/app/photos/forms.py b/app/photos/forms.py index 9fd5529..97359e0 100644 --- a/app/photos/forms.py +++ b/app/photos/forms.py @@ -34,20 +34,32 @@ class GalleryForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(GalleryForm, self).__init__(*args, **kwargs) + self.fields['images'].choices = [(image.id, mark_safe('%sqq%sqq%s' % (image.title, image.get_image_by_size('tn'), image.pk))) for image in LuxImage.objects.all()] + self.fields['images'].allow_tags = True - images = LuxImage.objects.all()[:100] - items = [] - for image in images: - items.append( - (image.pk, mark_safe('%sqq%sqq%s' % (image.title, image.get_image_by_size('tn'), image.pk))) - ) - +from django.utils.safestring import mark_safe + +class ImageChoiceField(forms.ModelMultipleChoiceField): + + def label_from_instance(self, obj): + + return mark_safe('%sqq%sqq%s' % (obj.title, obj.get_image_by_size('tn'), obj.pk)) - self.fields['images'].choices = items - self.fields['images'].allow_tags = True +class FKGalleryForm(forms.ModelForm): + class Meta: + fields = '__all__' + widgets = { + 'image': ImageChoiceField(queryset=LuxImage.objects.all()), + } + + def __init__(self, *args, **kwargs): + super(FKGalleryForm, self).__init__(*args, **kwargs) + self.fields['image'].choices = [(o.id, str(o.image.url)) for o in LuxImage.objects.all()] + self.fields['image'].allow_tags = True + class UploadZipForm(forms.Form): """ Handles the uploading of a gallery of photos packed in a .zip file |