Skip to content

Commit 0cdc26e

Browse files
committed
Fixes #13642: Move migration logic overrides from individual mgmt commands to core
1 parent 2503568 commit 0cdc26e

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

netbox/core/apps.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
from django.apps import AppConfig
2+
from django.db import models
3+
from django.db.migrations.operations import AlterModelOptions
4+
5+
from utilities.migration import custom_deconstruct
6+
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+
11+
# Use our custom destructor to ignore certain attributes when calculating field migrations
12+
models.Field.deconstruct = custom_deconstruct
213

314

415
class CoreConfig(AppConfig):

netbox/core/management/commands/makemigrations.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
# noinspection PyUnresolvedReferences
21
from django.conf import settings
32
from django.core.management.base import CommandError
43
from django.core.management.commands.makemigrations import Command as _Command
5-
from django.db import models
6-
from django.db.migrations.operations import AlterModelOptions
7-
8-
from utilities.migration import custom_deconstruct
9-
10-
# Monkey patch AlterModelOptions to ignore verbose name attributes
11-
AlterModelOptions.ALTER_OPTION_KEYS.remove('verbose_name')
12-
AlterModelOptions.ALTER_OPTION_KEYS.remove('verbose_name_plural')
13-
14-
# Set our custom deconstructor for fields
15-
models.Field.deconstruct = custom_deconstruct
164

175

186
class Command(_Command):

netbox/core/management/commands/migrate.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)