Last active
October 30, 2023 09:18
-
-
Save cnk/c14374bc0127291e99c415bf4fb3669b to your computer and use it in GitHub Desktop.
Add custom attributes to a Wagtail page - but only when creating.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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