For a small listing of events I used an InlinePanel
in my page model. Now I would like to filter these events by date, like I would do when using a @property
with subpages: date__gte=date.today()
for only displaying the future events on the page TourdatenIndexPag
. How to achieve that?
My implementation:
class EventItem(LinkFields):
date = models.DateField("Datum")
...
panels = [FieldPanel('date')]
class Meta:
abstract = True
class TourdatenPageEventItem(Orderable, EventItem):
page = ParentalKey('md.TourdatenIndexPage', related_name='event_items')
class TourdatenIndexPage(Page):
...
content_panels = Page.content_panels + [
InlinePanel('event_items', label="Events"),
]
Where and how could these event_items
be accessed and filtered?
Create a method on your page model to return the queryset you want:
class TourdatenIndexPage(Page):
def future_event_items(self):
return self.event_items.filter(date__gte=date.today())
Then, on your template, you can refer to self.future_event_items
:
{% for event in self.future_event_items %}
<li>{{ event.date }}</li>
{% endfor %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With