migration.py 719 B

12345678910111213141516171819202122232425262728293031323334
  1. from django.db import models
  2. from netbox.config import ConfigItem
  3. __all__ = (
  4. 'custom_deconstruct',
  5. )
  6. EXEMPT_ATTRS = (
  7. 'choices',
  8. 'help_text',
  9. 'verbose_name',
  10. )
  11. _deconstruct = models.Field.deconstruct
  12. def custom_deconstruct(field):
  13. """
  14. Imitate the behavior of the stock deconstruct() method, but ignore the field attributes listed above.
  15. """
  16. name, path, args, kwargs = _deconstruct(field)
  17. # Remove any ignored attributes
  18. for attr in EXEMPT_ATTRS:
  19. kwargs.pop(attr, None)
  20. # Ignore any field defaults which reference a ConfigItem
  21. kwargs = {
  22. k: v for k, v in kwargs.items() if not isinstance(v, ConfigItem)
  23. }
  24. return name, path, args, kwargs