Skip to content
This repository has been archived by the owner on Jun 13, 2022. It is now read-only.

Commit

Permalink
Use custom widget for template choices instead
Browse files Browse the repository at this point in the history
A bit more Djangonic than tweaking self.fields
  • Loading branch information
tomkins committed Feb 15, 2017
1 parent f00e7d7 commit 8898f23
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions blanc_basic_pages/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ class PageAdminForm(MPTTAdminForm):
class Meta:
model = Page
exclude = ()

def __init__(self, *args, **kwargs):
super(PageAdminForm, self).__init__(*args, **kwargs)

# The list of templates is defined in settings, however as we can't have dynamic choices in
# models due to migrations - we change the form choices instead.
self.fields['template_name'] = forms.ChoiceField(choices=TEMPLATE_CHOICES, required=False)
widgets = {
# The list of templates is defined in settings, however as we can't have dynamic
# choices in models due to migrations - we change the form choices instead.
'template_name': forms.widgets.Select(choices=TEMPLATE_CHOICES),
}

0 comments on commit 8898f23

Please sign in to comment.