Skip to content

Commit

Permalink
Fixes netbox-community#1289: Retain inside NAT assignment when editin…
Browse files Browse the repository at this point in the history
…g an IP address
  • Loading branch information
jeremystretch committed Jul 5, 2017
1 parent d5c1efa commit 54e7d01
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions netbox/utilities/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,6 @@ class ChainedFieldsMixin(forms.BaseForm):
def __init__(self, *args, **kwargs):
super(ChainedFieldsMixin, self).__init__(*args, **kwargs)

# if self.is_bound:
# assert False, self.data

for field_name, field in self.fields.items():

if isinstance(field, ChainedModelChoiceField):
Expand All @@ -492,6 +489,12 @@ def __init__(self, *args, **kwargs):

if filters_dict:
field.queryset = field.queryset.filter(**filters_dict)
elif not self.is_bound and self.instance and hasattr(self.instance, field_name):
obj = getattr(self.instance, field_name)
if obj is not None:
field.queryset = field.queryset.filter(pk=obj.pk)
else:
field.queryset = field.queryset.none()
elif not self.is_bound:
field.queryset = field.queryset.none()

Expand Down

0 comments on commit 54e7d01

Please sign in to comment.