mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-07 16:18:16 -06:00
Properly handle "False" as a text parameter when initialising NetBoxModelForm
This commit is contained in:
parent
e8a5fa32ce
commit
ce7343c279
@ -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 _
|
||||
@ -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)
|
||||
|
||||
|
@ -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, ''))
|
||||
|
Loading…
Reference in New Issue
Block a user