I am creating a Wagtail application where some models inherit fields from a base model. Unfortunately, these base fields are always displayed first in the form generated by Wagtail. For example:
class BaseModel(models.Model):
some_attribute = models.TextField()
class Meta:
abstract = True
content_panels = [
FieldPanel('some_attribute'),
]
@register_snippet
class ChildModel(BaseModel):
title = models.TextField()
content_panels = Page.content_panels + [
FieldPanel('title'),
]
In Wagtail admin in the ChildModel editor, some_attribute would be displayed above title now, which is not very intuitive to users. Is there a way to change this behaviour?
For snippets, the correct attribute name to use is panels
, not content_panels
. (For pages, the "content" in "content_panels" refers to the content tab rather than the "promote" tab - snippets don't have these tabs, unless you explicitly add them.) You probably also don't want to reference Page.content_panels
, because this isn't a page model.
Since you don't have a panels
attribute, it's falling back on listing the fields in definition order. Once you change content_panels
to panels
, you'll find that they get displayed in the order that you list them.