-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert all optional choice fields to use a null empty value #17761
Labels
complexity: medium
Requires a substantial but not unusual amount of effort to implement
netbox
status: accepted
This issue has been accepted for implementation
type: feature
Introduction of new functionality to the application
Milestone
Comments
These are the affected fields:
Audit scriptfrom django.apps import apps
from django.db import models
for model in apps.get_models():
fields = []
for field in model._meta.get_fields():
if isinstance(field, models.CharField) and field.choices and field.blank and not field.null:
fields.append(f"`{field.name}`")
if fields:
print(f"* {model._meta.label}: {', '.join(fields)}") |
jeremystretch
added a commit
that referenced
this issue
Oct 18, 2024
jeremystretch
added a commit
that referenced
this issue
Oct 21, 2024
jeremystretch
added a commit
that referenced
this issue
Nov 25, 2024
Merged
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
complexity: medium
Requires a substantial but not unusual amount of effort to implement
netbox
status: accepted
This issue has been accepted for implementation
type: feature
Introduction of new functionality to the application
NetBox version
v4.1.3
Feature type
Change to existing functionality
Triage priority
N/A
Proposed functionality
Several models include optional choices fields, such as
Cable.type
. Most (if not all) of these store an empty value as an empty string (''
) rather thannull
. This FR proposes:null
null
for these fieldsThe list of specific fields to be updated is TBD, but is expect to include any CharField for which
choices
is defined andnull
is False.Use case
The use of empty strings to represent empty values for these fields deviates from other fields (e.g. integer-based fields) and complicates the logic needed to achieve complex filtering (see #17575 for an example). This change will help us standardize the behavior of the data model in general.
Database changes
All CharFields which define a set of choices will be modified to store empty values as
null
in the database. Migrations will be included to effect this change on existing data.External dependencies
N/A
The text was updated successfully, but these errors were encountered: