Wagtail Page or Django model

48 views
Skip to first unread message

Davor Škalec

unread,
Aug 11, 2021, 12:42:44 PM8/11/21
to Wagtail support
Hi everyone,

I came over to Wagtail with a few years of Django experience and started working on a new project that opened up some questions for me which I couldn't find in the official docs.

For starters, is there a general rule about what should be a Wagtail Page and what should be a basic Django model? I'm going with the assumption that anything that should be clickable on the frontend should basically be a Wagtail Page and some other data that are used in multiple places in your site, but doesn't really have a landing page is a Django model. Would that be correct? 

Also, I've seen examples where you define something as a Wagtail Page and define all the fields you need directly there and other examples where you basically create a Django model and then on the Page itself just define a ForeignKey to that Django model. My question is what should be the correct approach there?

Thank you in advance.

Nick Pereira

unread,
Aug 11, 2021, 12:59:33 PM8/11/21
to Wagtail support
Hi Davor, in my past experience I've defined wagtail pages for any page type that I want to have fields editable on the wagtail admin that are related only to this page. If I have anything that I'm using in multiple places sitewide and I still want to enable editing via the wagtail admin interface I would create a regular django model and decorate it with the @register_snippet decorator https://docs.wagtail.io/en/stable/topics/snippets.html 

If it's a model that you don't think you'd need to have your content editors change, a regular django model could be fine and you'd manage that in the django-admin. That would be a decision that is made depending on the requirements of the project.

For your second question, I'm not as experienced with that, but I'd say if it's relevant to the page itself maybe it should be defined on the wagtail page model. If it's a field that you're sharing across models maybe the foreign key field to a different model makes more sense

Davor Škalec

unread,
Aug 24, 2021, 2:04:31 AM8/24/21
to Wagtail support
Hi Nick,

thank you for the reply and sorry for the slow response. I've done something in the line of what you've described - for the data that is re-used across multiple pages but doesn't need to have it's own URL on the frontend
I've used the @register_snippet decorator. The only thing which I'm not really satisfied with is that I can't seem to figure out how to expose multiple fields of my snippet in the snippet "list view" or how to implement some filtering there. Sure, I can do that by registering the model using the @modeladmin_register and there I can define the list_display, list_filter etc. , but there I don't have the option to select multiple entries and bulk delete them which is kind of important for my project so I'm still trying to figure out that one. 

Reply all
Reply to author
Forward
0 new messages