Skip to content

Instantly share code, notes, and snippets.

@gasman

gasman/models.py

Created Nov 12, 2015
Embed
What would you like to do?
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