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

30 lines
614 B
Python
Raw Normal View History

from django.db import models
2021-08-24 15:52:04 -04:00
from timezone_field import TimeZoneField
2021-08-24 15:52:04 -04:00
SKIP_FIELDS = (
TimeZoneField,
)
EXEMPT_ATTRS = (
'choices',
'help_text',
'verbose_name',
2021-08-24 15:52:04 -04:00
)
_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
2021-08-24 15:52:04 -04:00
if field.__class__ not in SKIP_FIELDS:
for attr in EXEMPT_ATTRS:
kwargs.pop(attr, None)
return name, path, args, kwargs