apps.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from django.apps import AppConfig
  2. from django.conf import settings
  3. from django.core.cache import cache
  4. from django.db import models
  5. from django.db.migrations.operations import AlterModelOptions
  6. from utilities.migration import custom_deconstruct
  7. # Ignore verbose_name & verbose_name_plural Meta options when calculating model migrations
  8. AlterModelOptions.ALTER_OPTION_KEYS.remove('verbose_name')
  9. AlterModelOptions.ALTER_OPTION_KEYS.remove('verbose_name_plural')
  10. # Use our custom destructor to ignore certain attributes when calculating field migrations
  11. models.Field.deconstruct = custom_deconstruct
  12. class CoreConfig(AppConfig):
  13. name = "core"
  14. def ready(self):
  15. from core.api import schema # noqa: F401
  16. from core.checks import check_duplicate_indexes # noqa: F401
  17. from netbox.models.features import register_models
  18. from . import data_backends, events, search # noqa: F401
  19. from netbox import context_managers # noqa: F401
  20. # Register models
  21. register_models(*self.get_models())
  22. # Clear Redis cache on startup in development mode
  23. if settings.DEBUG:
  24. try:
  25. cache.clear()
  26. except Exception:
  27. pass