add wip event occurrences
This commit is contained in:
@ -1,10 +1,20 @@
|
||||
from django.db import models
|
||||
from grapple.models import GraphQLImage, GraphQLInt, GraphQLStreamfield, GraphQLString
|
||||
from grapple.models import (
|
||||
GraphQLCollection,
|
||||
GraphQLForeignKey,
|
||||
GraphQLImage,
|
||||
GraphQLInt,
|
||||
GraphQLStreamfield,
|
||||
GraphQLString,
|
||||
)
|
||||
from modelcluster.fields import ParentalKey
|
||||
from wagtail import blocks
|
||||
from wagtail.admin.panels import FieldPanel, FieldRowPanel, HelpPanel, MultiFieldPanel
|
||||
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 Page
|
||||
from wagtail.models import Orderable, Page
|
||||
|
||||
from venues.models import VenuePage
|
||||
|
||||
|
||||
class EventIndex(Page):
|
||||
@ -17,6 +27,7 @@ class EventIndex(Page):
|
||||
class EventPage(Page):
|
||||
# no children
|
||||
subpage_types = []
|
||||
parent_page_types = ["events.EventIndex"]
|
||||
# should not be able to be shown in menus
|
||||
show_in_menus = False
|
||||
|
||||
@ -93,6 +104,18 @@ class EventPage(Page):
|
||||
heading="Priser og billettkjøp",
|
||||
children=ticket_panels,
|
||||
),
|
||||
MultiFieldPanel(
|
||||
children=[
|
||||
HelpPanel(
|
||||
heading="Forekomster",
|
||||
content=(
|
||||
"Om arrangementet går over flere dager, "
|
||||
"legg inn hver dag som en egen forekomst."
|
||||
),
|
||||
),
|
||||
InlinePanel("occurrences", min_num=1),
|
||||
]
|
||||
),
|
||||
]
|
||||
|
||||
graphql_fields = [
|
||||
@ -103,11 +126,40 @@ class EventPage(Page):
|
||||
GraphQLInt("price_regular"),
|
||||
GraphQLInt("price_student"),
|
||||
GraphQLInt("price_member"),
|
||||
GraphQLCollection(GraphQLForeignKey, "occurrences", "events.EventOccurrence"),
|
||||
]
|
||||
|
||||
|
||||
class EventOccurrence(models.Model):
|
||||
event = models.ForeignKey(EventPage, on_delete=models.CASCADE, related_name="occurrences")
|
||||
class EventOccurrence(Orderable):
|
||||
event = ParentalKey(EventPage, on_delete=models.CASCADE, related_name="occurrences")
|
||||
start = models.DateTimeField()
|
||||
end = models.DateTimeField(null=True, blank=True)
|
||||
venue = models.ForeignKey(
|
||||
VenuePage, on_delete=models.PROTECT, related_name="event_occurrences"
|
||||
)
|
||||
|
||||
panels = [
|
||||
FieldRowPanel(
|
||||
children=[
|
||||
FieldPanel("start", heading="Start"),
|
||||
FieldPanel("end", heading="Slutt"),
|
||||
],
|
||||
),
|
||||
FieldPanel("venue", heading="Lokale"),
|
||||
]
|
||||
|
||||
graphql_fields = [
|
||||
GraphQLString("start"),
|
||||
GraphQLString("end"),
|
||||
GraphQLForeignKey("venue", "venues.VenuePage"),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.start}--{self.end}"
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Forekomst"
|
||||
verbose_name_plural = "Forekomster"
|
||||
|
||||
|
||||
sample_legacy_event_json = """
|
||||
|
Reference in New Issue
Block a user