0

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?

fwinterl
  • 85
  • 1
  • 7

1 Answers1

1

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.

gasman
  • 23,691
  • 1
  • 38
  • 56
  • in order to get the BaseModel `panels` into the view, i then finally had to add `+ BaseModel.panels` to the `ChildModel.panels` array. – fwinterl Aug 18 '21 at 14:03