1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00
Jeremy Stretch 5f159795dd Closes #15042: Move model registration logic to AppConfigs (#15203)
* Closes #15042: Move model registration logic to AppConfigs

* Refactor register_model() to accept multiple models
2024-02-21 14:22:13 -05:00

25 lines
821 B
Python

from django.apps import AppConfig
from django.db import models
from django.db.migrations.operations import AlterModelOptions
from utilities.migration import custom_deconstruct
# Ignore verbose_name & verbose_name_plural Meta options when calculating model migrations
AlterModelOptions.ALTER_OPTION_KEYS.remove('verbose_name')
AlterModelOptions.ALTER_OPTION_KEYS.remove('verbose_name_plural')
# Use our custom destructor to ignore certain attributes when calculating field migrations
models.Field.deconstruct = custom_deconstruct
class CoreConfig(AppConfig):
name = "core"
def ready(self):
from core.api import schema # noqa
from netbox.models.features import register_models
from . import data_backends, search
# Register models
register_models(*self.get_models())