diff --git a/README.mdown b/README.mdown index cb16af7..186b582 100644 --- a/README.mdown +++ b/README.mdown @@ -33,6 +33,8 @@ Create an Event Container page in the Mezzanine admin (naming it something like ## Creating Templates +In addition to the documentation here, take a look at how the default templates in the `mezzanine_events/templates` directory are written. + ### Event pages The template for an Event page is `templates/pages/event.html`. @@ -60,7 +62,7 @@ Event pages default to being not visible in navigation, unless "show events in n The template for an Event Container page is `templates/pages/eventcontainer.html`. -Iterate over `page.children.all` to get at the events inside the container. You can then use all of the properties and template tags listed above on these objects. +Iterate over `page.eventcontainer.events` to get at the events inside the container. You can then use all of the properties and template tags listed above on these objects. The template filter `{{ page.eventcontainer|icalendar_url:"webcal" }}` can be used to produce a webcal URL. When a link containing this URL is clicked, the user's default calendaring app will subscribe to events in this eventcontainer. diff --git a/mezzanine_events/models.py b/mezzanine_events/models.py index 54f294e..da543dd 100644 --- a/mezzanine_events/models.py +++ b/mezzanine_events/models.py @@ -71,7 +71,7 @@ def save(self, *args, **kwargs): self.in_menus = "" super(Event, self).save(*args, **kwargs) - + class Meta: verbose_name = "Event" @@ -79,3 +79,7 @@ class EventContainer (Page): hide_children = models.BooleanField(default=True, verbose_name="Hide events in this container from navigation") class Meta: verbose_name = "Event Container" + + def events(self): + """Convenience method for getting at all events in a container, in the right order, from a template.""" + return self.children.published().order_by('_order') diff --git a/mezzanine_events/templates/pages/eventcontainer.html b/mezzanine_events/templates/pages/eventcontainer.html index 435a740..a49fdb9 100644 --- a/mezzanine_events/templates/pages/eventcontainer.html +++ b/mezzanine_events/templates/pages/eventcontainer.html @@ -10,10 +10,10 @@ -{% for child in page.children.published %} -

{{child.title}} {{child.event.date}} from {{child.event.start_time}} to {{child.event.end_time}}

- {{child.event.content|richtext_filter|truncatewords_html:40|safe}} - More info → +{% for event in page.eventcontainer.events %} +

{{event.title}} {{event.event.date}} from {{event.event.start_time}} to {{event.event.end_time}}

+ {{event.event.content|richtext_filter|truncatewords_html:40|safe}} + More info → {% endfor %} -{% endblock %} \ No newline at end of file +{% endblock %}