|
@@ -4,6 +4,7 @@ from collections import OrderedDict
|
|
|
|
|
|
|
|
from django import forms
|
|
from django import forms
|
|
|
from django.contrib.contenttypes.models import ContentType
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
|
|
+from django.core.exceptions import ObjectDoesNotExist
|
|
|
|
|
|
|
|
from utilities.forms import BootstrapMixin, BulkEditForm, LaxURLField
|
|
from utilities.forms import BootstrapMixin, BulkEditForm, LaxURLField
|
|
|
from .constants import CF_FILTER_DISABLED, CF_TYPE_BOOLEAN, CF_TYPE_DATE, CF_TYPE_INTEGER, CF_TYPE_SELECT, CF_TYPE_URL
|
|
from .constants import CF_FILTER_DISABLED, CF_TYPE_BOOLEAN, CF_TYPE_DATE, CF_TYPE_INTEGER, CF_TYPE_SELECT, CF_TYPE_URL
|
|
@@ -53,7 +54,14 @@ def get_custom_fields_for_model(content_type, filterable_only=False, bulk_edit=F
|
|
|
choices = [(cfc.pk, cfc) for cfc in cf.choices.all()]
|
|
choices = [(cfc.pk, cfc) for cfc in cf.choices.all()]
|
|
|
if not cf.required or bulk_edit or filterable_only:
|
|
if not cf.required or bulk_edit or filterable_only:
|
|
|
choices = [(None, '---------')] + choices
|
|
choices = [(None, '---------')] + choices
|
|
|
- field = forms.TypedChoiceField(choices=choices, coerce=int, required=cf.required)
|
|
|
|
|
|
|
+ # Check for a default choice
|
|
|
|
|
+ default_choice = None
|
|
|
|
|
+ if initial:
|
|
|
|
|
+ try:
|
|
|
|
|
+ default_choice = cf.choices.get(value=initial).pk
|
|
|
|
|
+ except ObjectDoesNotExist:
|
|
|
|
|
+ pass
|
|
|
|
|
+ field = forms.TypedChoiceField(choices=choices, coerce=int, required=cf.required, initial=default_choice)
|
|
|
|
|
|
|
|
# URL
|
|
# URL
|
|
|
elif cf.type == CF_TYPE_URL:
|
|
elif cf.type == CF_TYPE_URL:
|