from django import forms
from django.conf import settings

from mptt.forms import MPTTAdminForm

from .models import Page


TEMPLATE_CHOICES = getattr(settings, 'PAGE_TEMPLATES', (
    ('', 'Default'),
))


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)

@@ -298,112 +298,32 @@
  ()%0A
-%0A
     
-def __init__(self, *args, **kwargs):%0A        super(PageAdminForm, self).__init__(*args, **kwargs)%0A%0A
+    widgets = %7B%0A    
     
@@ -406,16 +406,30 @@
  dynamic
+%0A            #
  choices
@@ -435,18 +435,8 @@
 s in
-%0A        #
  mod
@@ -507,20 +507,12 @@
     
-self.fields%5B
+    
 'tem
@@ -526,29 +526,30 @@
 ame'
-%5D =
+:
  forms.
-ChoiceField
+widgets.Select
 (cho
@@ -573,22 +573,17 @@
 ICES
-, required=False)
+),%0A        %7D
 %0A

Use custom widget for template choices instead