0
votes

if I have a Page class like this:

class LocationPage(AppPageMixin, Page):
    template = 'locations/locations_list.html'
    url_config = 'location.urls'
    ...

It allows me to create pages dynamically off of the LocationPage by entering objects into my Admin Model. It took me forever to get this to work but I got it.

The issue that I am having now is that I can't seem to add custom fields to the LocationPage anymore. I just need a banner image, title, and subtitle. The rest of the content comes from a loop through my Admin Model. I did what one would normally do to add fields to a page model:

class LocationPage(AppPageMixin, Page):
    template = 'locations/locations_list.html'
    url_config = 'location.urls'

    banner_image = models.ForeignKey(
        "wagtailimages.Image",
        null=True,
        blank=False,
        on_delete=models.SET_NULL,
        related_name="+"
    )
    page_title = models.CharField(max_length=200, null=True, blank=False)
    page_subtitle = models.CharField(max_length=300, null=True, blank=False)

    panels = [
        FieldPanel('page_title'),
        FieldPanel('page_subtitle'),
        ImageChooserPanel('banner_image'),
    ]

I migrated, but when I go to my current page using LocationPage, or if I create a new page, the fields do not show. this documentation (https://wagtail-app-pages.readthedocs.io/en/latest/) does not mention anything about how to do this or if it is possible, but I'd say it's a pretty common requirement. Having to enter static content into the template defeats the purpose of using a cms. am I missing something?

1
Can you share the code for your AppPageMixin on the question. Just a thought, maybe you have used Model the AppPageMixin without it being an abstract class docs.djangoproject.com/en/3.0/topics/db/models/… - LB Ben Johnston
This is the only place that I am using it, I'm not sure what you mean. - JSum
What is AppPageMixin? I cannot see that mentioned in the Wagtail menu docs or the main Wagtail docs. Also the docs you have linked go to Wagtail menus but your questions refer to ModelAdmin (I think). - LB Ben Johnston
@LBBenJohnston Thank you for sticking with me, my apologies for the late response. I updated the link. I am using 'Wagtail App Pages', which has an AppPageMixin that you place on the Page model that will be the listing page to the collection. - JSum
The 'Location' model is a django model that I have setup as an AdminModel, to be controlled in Wagtail admin. I'm not sure if that is relevant. My issue is specifically with the fields I add to the LocationPage model not being available when I choose that model as the template for a wagtail page. It is because of 'Wagtail App Pages'. It does the job of retrieving and making pages for the data, but I've lost all editability. I wasn't expecting to be able to use editable pages for the DetailView's, but I don't understand why the main template ListView can't be editable. - JSum

1 Answers

1
votes

Sorry I didn't get to see this earlier, but I hope I can weigh in as the author of wagtail_app_pages. You're absolutely right to expect this to work, you should be able to add fields to your heart's content. I'm afraid I've never come across this behavior before though. If you're still having this issue, would it be possible to share a minimal setup to reproduce this issue?

Also, please feel free to let me know if you ran into documentation shortcomings. I'd like to improve the documentation, if at all possible.

[EDIT] actually, just wondering about something. Why are you using:

panels = [

instead of:

content_panels = [

or:

settings_panels = [

etc? Maybe this is a mixup from some non-page models? An AppPage is still, most definitely, a Page, so it should use the normal page panels for the admin