Skip to content

Instantly share code, notes, and snippets.

@gasman
Created August 6, 2015 10:17
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/cc65b011e9783dead200 to your computer and use it in GitHub Desktop.
Save gasman/cc65b011e9783dead200 to your computer and use it in GitHub Desktop.
from __future__ import unicode_literals
from django.db import models
from wagtail.wagtailcore.blocks import StructBlock, CharBlock, URLBlock, StreamBlock
from wagtail.wagtailcore.models import Page
from wagtail.wagtailcore.fields import StreamField, RichTextField
from wagtail.wagtailimages.blocks import ImageChooserBlock
from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
from wagtail.wagtailadmin.edit_handlers import FieldPanel, MultiFieldPanel, \
StreamFieldPanel
#this blocks image does not get loaded from fixture
class CarouselBlock(StructBlock):
image = ImageChooserBlock(icon='image')
caption = CharBlock(blank=True, null=True, required=False)
link = URLBlock(blank=True, null=True, required=False)
class Meta:
label = "Carousel Block"
template = "blocks/carousel.html"
class CarouselHomeBlock(StreamBlock):
carousel = CarouselBlock()
class Meta:
template = 'blocks/carousel_home.html'
label = 'Carousel'
class HomePage(Page):
#subpage_types
logo = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
icon = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)
carousel = StreamField(CarouselHomeBlock(), null=True, blank=True)
search_fields = ()
body = RichTextField(blank=True)
#custom properties and unicode() children() get_context() etc..
class Meta:
verbose_name = "Home page"
content_panels = [
MultiFieldPanel(Page.content_panels + [
FieldPanel('body', classname="full"),
], "Base"),
StreamFieldPanel('carousel'),
]
promote_panels = [
MultiFieldPanel(Page.promote_panels, "Common page configurations"),
MultiFieldPanel([
ImageChooserPanel('logo'),
ImageChooserPanel('icon'),
], "Display")
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment