26👍
✅
From the release notes of wagtail version 1.1:
Usually, an operation that retrieves a queryset of pages (such as
homepage.get_children()
) will return them as basic Page instances, which only include the core page data such as title. Thespecific()
method (e.g.homepage.get_children().specific()
) now allows them to be retrieved as their most specific type, using the minimum number of queries.
Therefore you don’t need your custom function in the upcoming release 1.1 anymore and you can change your template to:
{% for page in self.get_children.specific %}
{{ page.title }}
{% image page.representative_image width-400 %}
{% endfor %}
At least since version 0.8 the following should work, too, using specific
:
{% for page in self.get_children %}
{{ page.title }}
{% image page.specific.representative_image width-400 %}
{% endfor %}
6👍
I’ve found this solution: Add a function child_pages to the IndexPage:
class IndexPage(Page):
intro = RichTextField(blank=True)
def child_pages(self):
return ItemPage.objects.live().child_of(self)
content_panels = Page.content_panels + [
FieldPanel('intro', classname='full'),
]
subpage_types = ['myapp.ItemPage']
And this can be accessed in the template:
{% for page in self.child_pages %}
{{ page.title }}
{% image page.representative_image width-400 %}
{% endfor %}
- Django 'Manager' object is not iterable (but the code works in the manage.py shell)
- "Show all" for more than 200 items in Django Admin
- Check if a unique value exists before creating it
- Django: how to pass individual setting to manage.py
- Django Admin: How do I filter on an integer field for a specific range of values
Source:stackexchange.com