Created
October 11, 2019 21:09
-
-
Save ivan-vilches/eb7a4085dadbbcea1d1c2e3b7b024da4 to your computer and use it in GitHub Desktop.
This file contains 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 wagtail.core.models import Page | |
from wagtail.core.fields import RichTextField | |
from wagtail.admin.edit_handlers import FieldPanel | |
from wagtail.search import index | |
from wagtail.images.edit_handlers import ImageChooserPanel | |
class TallerIndexPage(Page): | |
template = "talleres/talleres_page.html" | |
is_creatable = False | |
intro = RichTextField(blank=True) | |
content_panels = Page.content_panels + [ | |
FieldPanel('intro', classname="full") | |
] | |
def get_context(self, request): | |
# Update context to include only published posts, ordered by reverse-chron | |
context = super().get_context(request) | |
talleres = self.get_children().live().order_by('-first_published_at') | |
context['talleres'] = talleres | |
return context | |
class Taller(Page): | |
template = "talleres/taller_single_page.html" | |
fecha_inicio_taller = models.DateField("Fecha Inicio Taller", null=True, blank=True) | |
lugar_taller = models.CharField(max_length=150, null=True, blank=True, verbose_name="Lugar donde se realizará el Taller") | |
descripcion = RichTextField(blank=False, null = False, verbose_name="Descripción del Taller") | |
contenido = RichTextField(blank=True, null = True, verbose_name="Todo el contenido extra del taller", default="<p>some HTML here</p>") | |
imagen_taller = models.ForeignKey( | |
"wagtailimages.Image", | |
null=True, | |
blank=True, | |
on_delete=models.SET_NULL, | |
related_name="+", | |
) | |
search_fields = Page.search_fields + [ | |
index.SearchField( | |
'descripcion'), | |
] | |
content_panels = Page.content_panels + [ | |
FieldPanel('fecha_inicio_taller'), | |
FieldPanel('lugar_taller'), | |
FieldPanel('descripcion'), | |
FieldPanel('contenido'), | |
ImageChooserPanel('imagen_taller'), | |
] | |
def get_context(self, request): | |
# Update context to include only published posts, ordered by reverse-chron | |
context = super().get_context(request) | |
listapost = Page.objects.live() | |
context['listapost'] = listapost | |
return context | |
parent_page_types = ['talleres.TallerIndexPage'] | |
class Meta: | |
verbose_name = 'Taller' | |
verbose_name_plural = 'Talleres' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment