Skip to content

Commit

Permalink
Properly handle "False" as a text parameter when initialising NetBoxM…
Browse files Browse the repository at this point in the history
…odelForm
  • Loading branch information
peteeckel committed Aug 20, 2024
1 parent e8a5fa3 commit 2baee77
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions netbox/netbox/forms/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json

from django import forms
from django.forms.fields import BooleanField, NullBooleanField
from django.contrib.contenttypes.models import ContentType
from django.db.models import Q
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -31,6 +32,15 @@ class NetBoxModelForm(CheckLastUpdatedMixin, CustomFieldsMixin, TagsMixin, forms
"""
fieldsets = ()

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

for key, value in self.initial.items():
if key not in self.fields:
continue
if isinstance(self.fields[key], (BooleanField, NullBooleanField)) and self.initial[key]=="False":
self.initial[key] = False

def _get_content_type(self):
return ContentType.objects.get_for_model(self._meta.model)

Expand Down
2 changes: 1 addition & 1 deletion netbox/utilities/querydict.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def prepare_cloned_fields(instance):
for key, value in attrs.items():
if type(value) in (list, tuple):
params.extend([(key, v) for v in value])
elif value is not None and (key.startswith('cf_') or value is not False):
elif value is not None:
params.append((key, value))
else:
params.append((key, ''))
Expand Down

0 comments on commit 2baee77

Please sign in to comment.