|
@@ -5,6 +5,7 @@ from io import StringIO
|
|
|
|
|
|
|
|
import django_filters
|
|
import django_filters
|
|
|
from django import forms
|
|
from django import forms
|
|
|
|
|
+from django.conf import settings
|
|
|
from django.forms.fields import JSONField as _JSONField, InvalidJSONInput
|
|
from django.forms.fields import JSONField as _JSONField, InvalidJSONInput
|
|
|
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
|
|
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
|
|
|
from django.db.models import Count
|
|
from django.db.models import Count
|
|
@@ -355,7 +356,15 @@ class DynamicModelChoiceField(DynamicModelChoiceMixin, forms.ModelChoiceField):
|
|
|
Override get_bound_field() to avoid pre-populating field choices with a SQL query. The field will be
|
|
Override get_bound_field() to avoid pre-populating field choices with a SQL query. The field will be
|
|
|
rendered only with choices set via bound data. Choices are populated on-demand via the APISelect widget.
|
|
rendered only with choices set via bound data. Choices are populated on-demand via the APISelect widget.
|
|
|
"""
|
|
"""
|
|
|
- pass
|
|
|
|
|
|
|
+
|
|
|
|
|
+ def clean(self, value):
|
|
|
|
|
+ """
|
|
|
|
|
+ When null option is enabled and "None" is sent as part of a form to be submitted, it is sent as the
|
|
|
|
|
+ string 'null'. This will check for that condition and gracefully handle the conversion to a NoneType.
|
|
|
|
|
+ """
|
|
|
|
|
+ if self.null_option is not None and value == settings.FILTERS_NULL_CHOICE_VALUE:
|
|
|
|
|
+ return None
|
|
|
|
|
+ return super().clean(value)
|
|
|
|
|
|
|
|
|
|
|
|
|
class DynamicModelMultipleChoiceField(DynamicModelChoiceMixin, forms.ModelMultipleChoiceField):
|
|
class DynamicModelMultipleChoiceField(DynamicModelChoiceMixin, forms.ModelMultipleChoiceField):
|