I use parent_page_types
and subpage_types
happily all around my Page-models.
But I'm stuck at allowing my class HomePage(Page)
only as a direct child at root level.
Any hints?
Try this:
parent_page_types = ['wagtailcore.Page']
also, for completeness, to allow only one instance of a Homepage, add this classmethod to your HomePage
:
@classmethod
def can_create_at(cls, parent):
# You can only create one of these!
return super(HomePage, cls).can_create_at(parent) \
and not cls.objects.exists()
First of all, thumbs up for @Serafeim answer, but I will post my answer for people searching for issue similar to mine.
I wanted to achieve the same thing but for a specifi parent in multi-site mode. Meaning I wanted to have multiple site "HomePage" but each "HomePage" can only include one "SearchIndexPage". So the above answer would be modified to
@classmethod
def can_create_at(cls, parent):
# You can only create one of these!
return super(SearchIndexPage, cls).can_create_at(parent) \
and parent.get_children().type(SearchIndexPage).count() == 0
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