Skip to content

Commit bed67a6

Browse files
committed
Remove unused schema field and squash migrations
1 parent e93de4b commit bed67a6

File tree

4 files changed

+60
-241
lines changed

4 files changed

+60
-241
lines changed
Lines changed: 60 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 5.2.5 on 2025-08-22 18:57
1+
# Generated by Django 5.2.6 on 2025-09-18 23:56
22

33
import django.core.validators
44
import django.db.models.deletion
@@ -16,182 +16,88 @@ class Migration(migrations.Migration):
1616
initial = True
1717

1818
dependencies = [
19-
("core", "0018_concrete_objecttype"),
20-
("extras", "0132_configcontextprofile"),
19+
('core', '0018_concrete_objecttype'),
20+
('extras', '0133_make_cf_minmax_decimal'),
2121
]
2222

2323
operations = [
2424
migrations.CreateModel(
25-
name="CustomObjectObjectType",
26-
fields=[],
25+
name='CustomObjectObjectType',
26+
fields=[
27+
],
2728
options={
28-
"proxy": True,
29-
"indexes": [],
30-
"constraints": [],
29+
'proxy': True,
30+
'indexes': [],
31+
'constraints': [],
3132
},
32-
bases=("core.objecttype",),
33+
bases=('core.objecttype',),
3334
),
3435
migrations.CreateModel(
35-
name="CustomObjectType",
36+
name='CustomObjectType',
3637
fields=[
37-
(
38-
"id",
39-
models.BigAutoField(
40-
auto_created=True, primary_key=True, serialize=False
41-
),
42-
),
43-
("created", models.DateTimeField(auto_now_add=True, null=True)),
44-
("last_updated", models.DateTimeField(auto_now=True, null=True)),
45-
(
46-
"custom_field_data",
47-
models.JSONField(
48-
blank=True,
49-
default=dict,
50-
encoder=utilities.json.CustomFieldJSONEncoder,
51-
),
52-
),
53-
("description", models.CharField(blank=True, max_length=200)),
54-
("comments", models.TextField(blank=True)),
55-
(
56-
"name",
57-
models.CharField(
58-
max_length=100,
59-
unique=True,
60-
validators=[
61-
django.core.validators.RegexValidator(
62-
message="Only lowercase alphanumeric characters and underscores are allowed.",
63-
regex="^[a-z0-9_]+$",
64-
),
65-
django.core.validators.RegexValidator(
66-
flags=re.RegexFlag["IGNORECASE"],
67-
inverse_match=True,
68-
message="Double underscores are not permitted in custom object object type names.",
69-
regex="__",
70-
),
71-
],
72-
),
73-
),
74-
("schema", models.JSONField(blank=True, default=dict)),
75-
("verbose_name", models.CharField(blank=True, max_length=100)),
76-
("verbose_name_plural", models.CharField(blank=True, max_length=100)),
77-
("slug", models.SlugField(max_length=100, unique=True)),
78-
(
79-
"tags",
80-
taggit.managers.TaggableManager(
81-
through="extras.TaggedItem", to="extras.Tag"
82-
),
83-
),
38+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
39+
('created', models.DateTimeField(auto_now_add=True, null=True)),
40+
('last_updated', models.DateTimeField(auto_now=True, null=True)),
41+
('custom_field_data', models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder)),
42+
('description', models.CharField(blank=True, max_length=200)),
43+
('comments', models.TextField(blank=True)),
44+
('name', models.CharField(max_length=100, unique=True, validators=[django.core.validators.RegexValidator(message='Only lowercase alphanumeric characters and underscores are allowed.', regex='^[a-z0-9_]+$'), django.core.validators.RegexValidator(flags=re.RegexFlag['IGNORECASE'], inverse_match=True, message='Double underscores are not permitted in custom object object type names.', regex='__')])),
45+
('version', models.CharField(blank=True, max_length=10)),
46+
('verbose_name', models.CharField(blank=True, max_length=100)),
47+
('verbose_name_plural', models.CharField(blank=True, max_length=100)),
48+
('slug', models.SlugField(max_length=100, unique=True)),
49+
('object_type', models.OneToOneField(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='custom_object_types', to='core.objecttype')),
50+
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
8451
],
8552
options={
86-
"verbose_name": "Custom Object Type",
87-
"ordering": ("name",),
53+
'verbose_name': 'Custom Object Type',
54+
'ordering': ('name',),
8855
},
8956
bases=(netbox.models.deletion.DeleteMixin, models.Model),
9057
),
9158
migrations.CreateModel(
92-
name="CustomObjectTypeField",
59+
name='CustomObjectTypeField',
9360
fields=[
94-
(
95-
"id",
96-
models.BigAutoField(
97-
auto_created=True, primary_key=True, serialize=False
98-
),
99-
),
100-
("created", models.DateTimeField(auto_now_add=True, null=True)),
101-
("last_updated", models.DateTimeField(auto_now=True, null=True)),
102-
("type", models.CharField(default="text", max_length=50)),
103-
("primary", models.BooleanField(default=False)),
104-
(
105-
"name",
106-
models.CharField(
107-
max_length=50,
108-
validators=[
109-
django.core.validators.RegexValidator(
110-
flags=re.RegexFlag["IGNORECASE"],
111-
message="Only alphanumeric characters and underscores are allowed.",
112-
regex="^[a-z0-9_]+$",
113-
),
114-
django.core.validators.RegexValidator(
115-
flags=re.RegexFlag["IGNORECASE"],
116-
inverse_match=True,
117-
message="Double underscores are not permitted in custom object field names.",
118-
regex="__",
119-
),
120-
],
121-
),
122-
),
123-
("label", models.CharField(blank=True, max_length=50)),
124-
("group_name", models.CharField(blank=True, max_length=50)),
125-
("description", models.CharField(blank=True, max_length=200)),
126-
("required", models.BooleanField(default=False)),
127-
("unique", models.BooleanField(default=False)),
128-
("search_weight", models.PositiveSmallIntegerField(default=500)),
129-
("filter_logic", models.CharField(default="loose", max_length=50)),
130-
("default", models.JSONField(blank=True, null=True)),
131-
("related_object_filter", models.JSONField(blank=True, null=True)),
132-
("weight", models.PositiveSmallIntegerField(default=100)),
133-
("validation_minimum", models.BigIntegerField(blank=True, null=True)),
134-
("validation_maximum", models.BigIntegerField(blank=True, null=True)),
135-
(
136-
"validation_regex",
137-
models.CharField(
138-
blank=True,
139-
max_length=500,
140-
validators=[utilities.validators.validate_regex],
141-
),
142-
),
143-
("ui_visible", models.CharField(default="always", max_length=50)),
144-
("ui_editable", models.CharField(default="yes", max_length=50)),
145-
("is_cloneable", models.BooleanField(default=False)),
146-
("comments", models.TextField(blank=True)),
147-
(
148-
"choice_set",
149-
models.ForeignKey(
150-
blank=True,
151-
null=True,
152-
on_delete=django.db.models.deletion.PROTECT,
153-
related_name="choices_for_object_type",
154-
to="extras.customfieldchoiceset",
155-
),
156-
),
157-
(
158-
"custom_object_type",
159-
models.ForeignKey(
160-
on_delete=django.db.models.deletion.CASCADE,
161-
related_name="fields",
162-
to="netbox_custom_objects.customobjecttype",
163-
),
164-
),
165-
(
166-
"related_object_type",
167-
models.ForeignKey(
168-
blank=True,
169-
null=True,
170-
on_delete=django.db.models.deletion.PROTECT,
171-
to="core.objecttype",
172-
),
173-
),
61+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
62+
('created', models.DateTimeField(auto_now_add=True, null=True)),
63+
('last_updated', models.DateTimeField(auto_now=True, null=True)),
64+
('type', models.CharField(default='text', max_length=50)),
65+
('primary', models.BooleanField(default=False)),
66+
('name', models.CharField(max_length=50, validators=[django.core.validators.RegexValidator(flags=re.RegexFlag['IGNORECASE'], message='Only alphanumeric characters and underscores are allowed.', regex='^[a-z0-9_]+$'), django.core.validators.RegexValidator(flags=re.RegexFlag['IGNORECASE'], inverse_match=True, message='Double underscores are not permitted in custom object field names.', regex='__')])),
67+
('label', models.CharField(blank=True, max_length=50)),
68+
('group_name', models.CharField(blank=True, max_length=50)),
69+
('description', models.CharField(blank=True, max_length=200)),
70+
('required', models.BooleanField(default=False)),
71+
('unique', models.BooleanField(default=False)),
72+
('search_weight', models.PositiveSmallIntegerField(default=500)),
73+
('filter_logic', models.CharField(default='loose', max_length=50)),
74+
('default', models.JSONField(blank=True, null=True)),
75+
('related_object_filter', models.JSONField(blank=True, null=True)),
76+
('weight', models.PositiveSmallIntegerField(default=100)),
77+
('validation_minimum', models.BigIntegerField(blank=True, null=True)),
78+
('validation_maximum', models.BigIntegerField(blank=True, null=True)),
79+
('validation_regex', models.CharField(blank=True, max_length=500, validators=[utilities.validators.validate_regex])),
80+
('ui_visible', models.CharField(default='always', max_length=50)),
81+
('ui_editable', models.CharField(default='yes', max_length=50)),
82+
('is_cloneable', models.BooleanField(default=False)),
83+
('comments', models.TextField(blank=True)),
84+
('choice_set', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='choices_for_object_type', to='extras.customfieldchoiceset')),
85+
('custom_object_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='fields', to='netbox_custom_objects.customobjecttype')),
86+
('related_object_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='core.objecttype')),
17487
],
17588
options={
176-
"verbose_name": "custom object type field",
177-
"verbose_name_plural": "custom object type fields",
178-
"ordering": ["group_name", "weight", "name"],
89+
'verbose_name': 'custom object type field',
90+
'verbose_name_plural': 'custom object type fields',
91+
'ordering': ['group_name', 'weight', 'name'],
17992
},
18093
bases=(netbox.models.deletion.DeleteMixin, models.Model),
18194
),
18295
migrations.AddConstraint(
183-
model_name="customobjecttype",
184-
constraint=models.UniqueConstraint(
185-
django.db.models.functions.text.Lower("name"),
186-
name="netbox_custom_objects_customobjecttype_name",
187-
violation_error_message="A Custom Object Type with this name already exists.",
188-
),
96+
model_name='customobjecttype',
97+
constraint=models.UniqueConstraint(django.db.models.functions.text.Lower('name'), name='netbox_custom_objects_customobjecttype_name', violation_error_message='A Custom Object Type with this name already exists.'),
18998
),
19099
migrations.AddConstraint(
191-
model_name="customobjecttypefield",
192-
constraint=models.UniqueConstraint(
193-
fields=("name", "custom_object_type"),
194-
name="netbox_custom_objects_customobjecttypefield_unique_name",
195-
),
100+
model_name='customobjecttypefield',
101+
constraint=models.UniqueConstraint(fields=('name', 'custom_object_type'), name='netbox_custom_objects_customobjecttypefield_unique_name'),
196102
),
197103
]

netbox_custom_objects/migrations/0002_customobjecttype_version.py

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

netbox_custom_objects/migrations/0003_customobjecttype_object_type.py

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

netbox_custom_objects/models.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ class CustomObjectType(PrimaryModel):
187187
),
188188
)
189189
version = models.CharField(max_length=10, blank=True)
190-
schema = models.JSONField(blank=True, default=dict)
191190
verbose_name = models.CharField(max_length=100, blank=True)
192191
verbose_name_plural = models.CharField(max_length=100, blank=True)
193192
slug = models.SlugField(max_length=100, unique=True, db_index=True)
@@ -280,20 +279,6 @@ def get_cached_through_models(cls, custom_object_type_id):
280279
"""
281280
return cls._through_model_cache.get(custom_object_type_id, {})
282281

283-
@property
284-
def formatted_schema(self):
285-
result = "<ul>"
286-
for field_name, field in self.schema.items():
287-
field_type = field.get("type")
288-
if field_type in ["object", "multiobject"]:
289-
content_type = ContentType.objects.get(
290-
app_label=field["app_label"], model=field["model"]
291-
)
292-
field = content_type
293-
result += f"<li>{field_name}: {field}</li>"
294-
result += "</ul>"
295-
return result
296-
297282
def get_absolute_url(self):
298283
return reverse("plugins:netbox_custom_objects:customobjecttype", args=[self.pk])
299284

0 commit comments

Comments
 (0)