1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixed default value for boolean fields

This commit is contained in:
Jeremy Stretch
2016-08-18 11:44:40 -04:00
parent 9bdb50c33e
commit 6f44f4245e
3 changed files with 12 additions and 4 deletions

View File

@ -25,7 +25,14 @@ def get_custom_fields_for_model(content_type, bulk_editing=False):
(True, 'True'),
(False, 'False'),
)
field = forms.NullBooleanField(required=cf.required, widget=forms.Select(choices=choices))
if cf.default.lower() in ['true', 'yes', '1']:
initial = True
elif cf.default.lower() in ['false', 'no', '0']:
initial = False
else:
initial = None
field = forms.NullBooleanField(required=cf.required, initial=initial,
widget=forms.Select(choices=choices))
# Date
elif cf.type == CF_TYPE_DATE:

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-08-17 18:42
# Generated by Django 1.10 on 2016-08-18 15:43
from __future__ import unicode_literals
from django.db import migrations, models
@ -23,7 +23,7 @@ class Migration(migrations.Migration):
('label', models.CharField(blank=True, help_text=b"Name of the field as displayed to users (if not provided, the field's name will be used)", max_length=50)),
('description', models.CharField(blank=True, max_length=100)),
('required', models.BooleanField(default=False, help_text=b'Determines whether this field is required when creating new objects or editing an existing object.')),
('default', models.CharField(blank=True, help_text=b'Default value for the field. N/A for selection fields.', max_length=100)),
('default', models.CharField(blank=True, help_text=b'Default value for the field. Use "true" or "false" for booleans. N/A for selection fields.', max_length=100)),
('obj_type', models.ManyToManyField(help_text=b'The object(s) to which this field applies.', related_name='custom_fields', to='contenttypes.ContentType', verbose_name=b'Object(s)')),
],
options={

View File

@ -90,7 +90,8 @@ class CustomField(models.Model):
description = models.CharField(max_length=100, blank=True)
required = models.BooleanField(default=False, help_text="Determines whether this field is required when creating "
"new objects or editing an existing object.")
default = models.CharField(max_length=100, blank=True, help_text="Default value for the field. N/A for selection "
default = models.CharField(max_length=100, blank=True, help_text="Default value for the field. Use \"true\" or "
"\"false\" for booleans. N/A for selection "
"fields.")
class Meta: