add event categories

This commit is contained in:
2024-05-13 02:20:26 +02:00
parent 80421b537a
commit 9b77ac0203
8 changed files with 143 additions and 13 deletions

View File

@ -1,5 +1,9 @@
from django import forms
from django.db import models
from django.utils.translation import gettext_lazy as _
from grapple.helpers import register_query_field
from grapple.models import (
GraphQLBoolean,
GraphQLCollection,
GraphQLForeignKey,
GraphQLImage,
@ -7,12 +11,13 @@ from grapple.models import (
GraphQLStreamfield,
GraphQLString,
)
from modelcluster.fields import ParentalKey
from modelcluster.fields import ParentalKey, ParentalManyToManyField
from wagtail import blocks
from wagtail.admin.panels import FieldPanel, FieldRowPanel, HelpPanel, InlinePanel, MultiFieldPanel
from wagtail.fields import StreamField
from wagtail.images.blocks import ImageChooserBlock
from wagtail.models import Orderable, Page
from wagtail.snippets.models import register_snippet
from venues.models import VenuePage
@ -24,6 +29,39 @@ class EventIndex(Page):
graphql_fields = []
@register_snippet
@register_query_field("eventCategory", "eventCategories")
class EventCategory(models.Model):
name = models.CharField(
max_length=100,
null=True,
)
slug = models.SlugField(
verbose_name=_("slug"),
max_length=255,
help_text=_("The name of the category as it will appear in URLs."),
)
show_in_filters = models.BooleanField(
default=False, help_text="Skal denne kategorien være mulig å filtrere på i programmet?"
)
panels = [FieldPanel("name"), FieldPanel("slug"), FieldPanel("show_in_filters")]
graphql_fields = [
GraphQLString("name"),
GraphQLString("slug"),
GraphQLBoolean("show_in_filters"),
]
class Meta:
verbose_name = "Event category"
verbose_name_plural = "Event categories"
ordering = ["name"]
def __str__(self):
return self.name
class EventPage(Page):
# no children
subpage_types = []
@ -62,6 +100,11 @@ class EventPage(Page):
]
)
categories = ParentalManyToManyField(
"events.EventCategory",
blank=True,
)
ticket_url = models.URLField(
blank=True,
max_length=512,
@ -100,6 +143,7 @@ class EventPage(Page):
content_panels = Page.content_panels + [
FieldPanel("featured_image"),
FieldPanel("body"),
FieldPanel("categories", widget=forms.CheckboxSelectMultiple),
MultiFieldPanel(
heading="Priser og billettkjøp",
children=ticket_panels,
@ -126,6 +170,7 @@ class EventPage(Page):
GraphQLInt("price_regular"),
GraphQLInt("price_student"),
GraphQLInt("price_member"),
GraphQLCollection(GraphQLForeignKey, "categories", "events.EventCategory"),
GraphQLCollection(GraphQLForeignKey, "occurrences", "events.EventOccurrence"),
]