mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #4240: Fix exception when filtering foreign keys by NULL
This commit is contained in:
@ -11,6 +11,7 @@
|
|||||||
* [#4232](https://github.com/netbox-community/netbox/issues/4232) - Enforce consistent background striping in rack elevations
|
* [#4232](https://github.com/netbox-community/netbox/issues/4232) - Enforce consistent background striping in rack elevations
|
||||||
* [#4235](https://github.com/netbox-community/netbox/issues/4235) - Fix API representation of `content_type` for export templates
|
* [#4235](https://github.com/netbox-community/netbox/issues/4235) - Fix API representation of `content_type` for export templates
|
||||||
* [#4239](https://github.com/netbox-community/netbox/issues/4239) - Fix exception when selecting all filtered objects during bulk edit
|
* [#4239](https://github.com/netbox-community/netbox/issues/4239) - Fix exception when selecting all filtered objects during bulk edit
|
||||||
|
* [#4240](https://github.com/netbox-community/netbox/issues/4240) - Fix exception when filtering foreign keys by NULL
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -2,8 +2,9 @@ import csv
|
|||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
import yaml
|
|
||||||
|
|
||||||
|
import django_filters
|
||||||
|
import yaml
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.postgres.forms.jsonb import JSONField as _JSONField, InvalidJSONInput
|
from django.contrib.postgres.forms.jsonb import JSONField as _JSONField, InvalidJSONInput
|
||||||
@ -564,18 +565,17 @@ class TagFilterField(forms.MultipleChoiceField):
|
|||||||
|
|
||||||
|
|
||||||
class DynamicModelChoiceMixin:
|
class DynamicModelChoiceMixin:
|
||||||
field_modifier = ''
|
filter = django_filters.ModelChoiceFilter
|
||||||
|
|
||||||
def get_bound_field(self, form, field_name):
|
def get_bound_field(self, form, field_name):
|
||||||
bound_field = BoundField(form, self, field_name)
|
bound_field = BoundField(form, self, field_name)
|
||||||
|
|
||||||
# Modify the QuerySet of the field before we return it. Limit choices to any data already bound: Options
|
# Modify the QuerySet of the field before we return it. Limit choices to any data already bound: Options
|
||||||
# will be populated on-demand via the APISelect widget.
|
# will be populated on-demand via the APISelect widget.
|
||||||
field_name = '{}{}'.format(self.to_field_name or 'pk', self.field_modifier)
|
data = bound_field.data or bound_field.initial
|
||||||
if bound_field.data:
|
if data:
|
||||||
self.queryset = self.queryset.filter(**{field_name: self.prepare_value(bound_field.data)})
|
filter = self.filter(field_name=self.to_field_name or 'pk', queryset=self.queryset)
|
||||||
elif bound_field.initial:
|
self.queryset = filter.filter(self.queryset, data)
|
||||||
self.queryset = self.queryset.filter(**{field_name: self.prepare_value(bound_field.initial)})
|
|
||||||
else:
|
else:
|
||||||
self.queryset = self.queryset.none()
|
self.queryset = self.queryset.none()
|
||||||
|
|
||||||
@ -594,7 +594,7 @@ class DynamicModelMultipleChoiceField(DynamicModelChoiceMixin, forms.ModelMultip
|
|||||||
"""
|
"""
|
||||||
A multiple-choice version of DynamicModelChoiceField.
|
A multiple-choice version of DynamicModelChoiceField.
|
||||||
"""
|
"""
|
||||||
field_modifier = '__in'
|
filter = django_filters.ModelMultipleChoiceFilter
|
||||||
|
|
||||||
|
|
||||||
class LaxURLField(forms.URLField):
|
class LaxURLField(forms.URLField):
|
||||||
|
Reference in New Issue
Block a user