mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-20 16:01:34 +02:00
* Convert ObjectType to a concrete child model of ContentType * Add public flag to ObjectType * Catch post_migrate signal to update ObjectTypes * Reference ObjectType records instead of registry for feature support * Automatically create ObjectTypes * Introduce has_feature() utility function * ObjectTypeManager should not inherit from ContentTypeManager * Misc cleanup * Don't populate ObjectTypes during migration * Don't automatically create ObjectTypes when a ContentType is created * Fix test * Extend has_feature() to accept a model or OT/CT * Misc cleanup * Deprecate get_for_id() on ObjectTypeManager * Rename contenttypes.py to object_types.py * Add index to features ArrayField * Keep FK & M2M fields pointing to ContentType * Add get_for_models() to ObjectTypeManager * Add tests for manager methods & utility functions * Fix migrations for M2M relations to ObjectType * model_is_public() should return False for non-core & non-plugin models * Order ObjectType by app_label & model name * Resolve migrations conflict
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import core.models.contenttypes
|
||||
import core.models.object_types
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class Migration(migrations.Migration):
|
||||
},
|
||||
bases=('contenttypes.contenttype',),
|
||||
managers=[
|
||||
('objects', core.models.contenttypes.ObjectTypeManager()),
|
||||
('objects', core.models.object_types.ObjectTypeManager()),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
||||
63
netbox/core/migrations/0018_concrete_objecttype.py
Normal file
63
netbox/core/migrations/0018_concrete_objecttype.py
Normal file
@@ -0,0 +1,63 @@
|
||||
import django.contrib.postgres.fields
|
||||
import django.contrib.postgres.indexes
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('contenttypes', '0002_remove_content_type_name'),
|
||||
('core', '0017_objectchange_message'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
# Delete the proxy model from the migration state
|
||||
migrations.DeleteModel(
|
||||
name='ObjectType',
|
||||
),
|
||||
# Create the new concrete model
|
||||
migrations.CreateModel(
|
||||
name='ObjectType',
|
||||
fields=[
|
||||
(
|
||||
'contenttype_ptr',
|
||||
models.OneToOneField(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
parent_link=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
to='contenttypes.contenttype',
|
||||
related_name='object_type'
|
||||
)
|
||||
),
|
||||
(
|
||||
'public',
|
||||
models.BooleanField(
|
||||
default=False
|
||||
)
|
||||
),
|
||||
(
|
||||
'features',
|
||||
django.contrib.postgres.fields.ArrayField(
|
||||
base_field=models.CharField(max_length=50),
|
||||
default=list,
|
||||
size=None
|
||||
)
|
||||
),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'object type',
|
||||
'verbose_name_plural': 'object types',
|
||||
'ordering': ('app_label', 'model'),
|
||||
'indexes': [
|
||||
django.contrib.postgres.indexes.GinIndex(
|
||||
fields=['features'],
|
||||
name='core_object_feature_aec4de_gin'
|
||||
),
|
||||
]
|
||||
},
|
||||
bases=('contenttypes.contenttype',),
|
||||
managers=[],
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user