I'm using the wagtailmenus library with some custom models as described here. Nothing major, it just adds a language field:
class TranslatableFlatMenu(AbstractFlatMenu):
language = models.CharField(choices=TRANSLATION_CHOICES, help_text='For what language the menu should be used', max_length=13)
content_panels = (
MultiFieldPanel(
heading=_("Menu Details"),
children=(
FieldPanel("title"),
FieldPanel("site"),
FieldPanel("handle"),
FieldPanel("heading"),
FieldPanel("language"),
)
),
FlatMenuItemsInlinePanel(),
)
class TranslatableFlatMenuItem(AbstractFlatMenuItem):
menu = ParentalKey(
TranslatableFlatMenu,
on_delete=models.CASCADE,
related_name=settings.FLAT_MENU_ITEMS_RELATED_NAME,
)
This works great, however I would like to display the field here:
Now for regular models I can use ModelAdmin and pass list_display
, but wagtailmenus seems to already register the menus itself. Is it possible to still change the list_display
property somehow so I can display the language in the list?
I'm not to well-versed on wagtailmenus, but it thinks WAGTAILMENUS_FLAT_MENUS_MODELADMIN_CLASS is the setting you're looking for.
To change the fields in list_display
, you would have to subclass wagtailmenus; FlatMenuAdmin
and override its get_list_display
function:
class TranslatableFlatMenuAdmin(FlatMenuAdmin):
def get_list_display(self, request):
if self.is_multisite_listing(request):
return ('title', 'language', 'handle_formatted', 'site', 'items')
return ('title', 'language', 'handle_formatted', 'items')
then in your settings.py add something like:
WAGTAILMENUS_FLAT_MENUS_MODELADMIN_CLASS = "project.app.admin.TranslatableFlatMenuAdmin"