mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
#2359: Extended exempt attributes to 'migrate' command
This commit is contained in:
@ -0,0 +1,28 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
EXEMPT_ATTRS = [
|
||||||
|
'choices',
|
||||||
|
'help_text',
|
||||||
|
'verbose_name',
|
||||||
|
]
|
||||||
|
|
||||||
|
_deconstruct = models.Field.deconstruct
|
||||||
|
|
||||||
|
|
||||||
|
def custom_deconstruct(field):
|
||||||
|
"""
|
||||||
|
Imitate the behavior of the stock deconstruct() method, but ignore the field attributes listed above.
|
||||||
|
"""
|
||||||
|
name, path, args, kwargs = _deconstruct(field)
|
||||||
|
|
||||||
|
# Remove any ignored attributes
|
||||||
|
for attr in EXEMPT_ATTRS:
|
||||||
|
kwargs.pop(attr, None)
|
||||||
|
|
||||||
|
# A hack to accommodate TimeZoneField, which employs a custom deconstructor to check whether the default choices
|
||||||
|
# have changed
|
||||||
|
if hasattr(field, 'CHOICES'):
|
||||||
|
kwargs['choices'] = field.CHOICES
|
||||||
|
|
||||||
|
return name, path, args, kwargs
|
||||||
|
@ -1,32 +1,6 @@
|
|||||||
|
# noinspection PyUnresolvedReferences
|
||||||
from django.core.management.commands.makemigrations import Command
|
from django.core.management.commands.makemigrations import Command
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from . import custom_deconstruct
|
||||||
|
|
||||||
EXEMPT_ATTRS = [
|
|
||||||
'choices',
|
|
||||||
'help_text',
|
|
||||||
'verbose_name',
|
|
||||||
]
|
|
||||||
|
|
||||||
_deconstruct = models.Field.deconstruct
|
|
||||||
|
|
||||||
|
|
||||||
def custom_deconstruct(field):
|
|
||||||
"""
|
|
||||||
Imitate the behavior of the stock deconstruct() method, but ignore the field attributes listed above.
|
|
||||||
"""
|
|
||||||
name, path, args, kwargs = _deconstruct(field)
|
|
||||||
|
|
||||||
# Remove any ignored attributes
|
|
||||||
for attr in EXEMPT_ATTRS:
|
|
||||||
kwargs.pop(attr, None)
|
|
||||||
|
|
||||||
# A hack to accommodate TimeZoneField, which employs a custom deconstructor to check whether the default choices
|
|
||||||
# have changed
|
|
||||||
if hasattr(field, 'CHOICES'):
|
|
||||||
kwargs['choices'] = field.CHOICES
|
|
||||||
|
|
||||||
return name, path, args, kwargs
|
|
||||||
|
|
||||||
|
|
||||||
models.Field.deconstruct = custom_deconstruct
|
models.Field.deconstruct = custom_deconstruct
|
||||||
|
6
netbox/utilities/management/commands/migrate.py
Normal file
6
netbox/utilities/management/commands/migrate.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# noinspection PyUnresolvedReferences
|
||||||
|
from django.core.management.commands.migrate import Command
|
||||||
|
from django.db import models
|
||||||
|
from . import custom_deconstruct
|
||||||
|
|
||||||
|
models.Field.deconstruct = custom_deconstruct
|
Reference in New Issue
Block a user