Created
October 10, 2019 21:23
-
-
Save ivan-vilches/c2fee85db494df9bbda3388836c9b0ee to your computer and use it in GitHub Desktop.
avoid select pages wagtail
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" | |
intro = RichTextField(blank=True) | |
content_panels = Page.content_panels + [ | |
FieldPanel('intro', classname="full") | |
] | |
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'), | |
] | |
class Meta: | |
verbose_name = 'Taller' | |
verbose_name_plural = 'Talleres' |
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 wagtail.contrib.modeladmin.options import ( | |
ModelAdmin, modeladmin_register) | |
from .models import Taller | |
class TallerAdmin(ModelAdmin): | |
model = Taller | |
menu_label = 'Talleres' # ditch this to use verbose_name_plural from model | |
menu_icon = 'pilcrow' # change as required | |
menu_order = 200 # will put in 3rd place (000 being 1st, 100 2nd) | |
add_to_settings_menu = False # or True to add your model to the Settings sub-menu | |
# or True to exclude pages of this type from Wagtail's explorer view | |
exclude_from_explorer = False | |
list_display = ('title', 'first_published_at', 'fecha_inicio_taller' ) | |
list_filter = ('first_published_at', 'fecha_inicio_taller') | |
search_fields = ('title', 'fecha_inicio_taller') | |
# Now you just need to register your customised ModelAdmin class with Wagtail | |
modeladmin_register(TallerAdmin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment