Skip to content

Instantly share code, notes, and snippets.

@cnk
Last active October 30, 2023 09:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cnk/c14374bc0127291e99c415bf4fb3669b to your computer and use it in GitHub Desktop.
Save cnk/c14374bc0127291e99c415bf4fb3669b to your computer and use it in GitHub Desktop.
Add custom attributes to a Wagtail page - but only when creating.
class CourseIndexPage(Page):
# ..... fields ......
base_form_class=CourseIndexPageForm
class CourseIndexPageForm(WagtailAdminPageForm):
def __init__(self, *args, **kwargs):
"""
Sets up the Course selector to treat selecting null for the Edition as setting it to "current".
Also makes show_in_menus default to True.
"""
instance = kwargs.get('instance')
if instance is None or instance.pk is None:
kwargs.update({'initial': {'show_in_menus': True}})
super().__init__(*args, **kwargs)
# Changes the "-------" string that Django uses by default for the NULL ForeignKey choice to "current".
self.fields['default_catalog_edition'].empty_label = 'current'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment