Created
November 12, 2015 15:56
-
-
Save gasman/57c363fa6f507f5be152 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.utils.translation import ugettext_lazy as _ | |
from django.utils.encoding import python_2_unicode_compatible | |
from modelcluster.models import ClusterableModel | |
from modelcluster.fields import ParentalKey | |
from wagtail.wagtailcore.models import Orderable | |
from wagtail.wagtailadmin.edit_handlers import FieldPanel, InlinePanel | |
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel | |
from wagtail.wagtailsnippets.models import register_snippet | |
class GalleryItem(models.Model): | |
image = models.ForeignKey( | |
'wagtailimages.Image', null=True, blank=True, | |
on_delete=models.SET_NULL, related_name='+') | |
source = models.CharField( | |
max_length=255, verbose_name=_('Source'), | |
help_text=_('Author/Origin of an image.')) | |
alt_text = models.CharField( | |
max_length=255, blank=True, default='', | |
help_text=_('Text displayed in image alt tag.')) | |
description = models.CharField( | |
max_length=255, blank=True, default='', | |
help_text=_('Short description of an image')) | |
panels = [ | |
ImageChooserPanel('image'), | |
FieldPanel('source'), | |
FieldPanel('alt_text'), | |
FieldPanel('description') | |
] | |
class Meta: | |
abstract = True | |
class GallerySnippetGalleryItems(Orderable, GalleryItem): | |
item = ParentalKey( | |
'galleries.GallerySnippet', related_name='related_gallery_items') | |
@python_2_unicode_compatible | |
@register_snippet | |
class GallerySnippet(ClusterableModel): | |
title = models.CharField(max_length=80, verbose_name=_('Gallery title')) | |
created_at = models.DateField(verbose_name=_('Date created')) | |
panels = [ | |
FieldPanel('title', classname='col8'), | |
FieldPanel('created_at', classname='col4'), | |
InlinePanel('related_gallery_items', label='Item') | |
] | |
def __str__(self): | |
return self.title |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment