2018-08-15 15:02:58 -04:00
|
|
|
from django.db import models
|
|
|
|
|
2022-06-23 17:44:19 -04:00
|
|
|
from netbox.config import ConfigItem
|
|
|
|
|
2023-04-14 10:33:53 -04:00
|
|
|
__all__ = (
|
|
|
|
'custom_deconstruct',
|
|
|
|
)
|
|
|
|
|
2018-08-15 15:02:58 -04:00
|
|
|
|
2021-08-24 15:52:04 -04:00
|
|
|
EXEMPT_ATTRS = (
|
2018-08-15 15:02:58 -04:00
|
|
|
'choices',
|
|
|
|
'help_text',
|
|
|
|
'verbose_name',
|
2021-08-24 15:52:04 -04:00
|
|
|
)
|
2018-08-15 15:02:58 -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
|
2024-03-21 10:38:58 -04:00
|
|
|
for attr in EXEMPT_ATTRS:
|
|
|
|
kwargs.pop(attr, None)
|
2018-08-15 15:02:58 -04:00
|
|
|
|
2022-06-23 17:44:19 -04:00
|
|
|
# Ignore any field defaults which reference a ConfigItem
|
|
|
|
kwargs = {
|
|
|
|
k: v for k, v in kwargs.items() if not isinstance(v, ConfigItem)
|
|
|
|
}
|
|
|
|
|
2018-08-15 15:02:58 -04:00
|
|
|
return name, path, args, kwargs
|