Skip to content

Instantly share code, notes, and snippets.

@gasman
Created November 12, 2015 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gasman/57c363fa6f507f5be152 to your computer and use it in GitHub Desktop.
Save gasman/57c363fa6f507f5be152 to your computer and use it in GitHub Desktop.
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