Skip to content

Commit f8576d4

Browse files
committed
Add correct migration
1 parent 56bb51d commit f8576d4

File tree

1 file changed

+177
-0
lines changed

1 file changed

+177
-0
lines changed
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# Generated by Django 5.2.5 on 2025-08-18 17:15
2+
3+
import django.core.validators
4+
import django.db.models.deletion
5+
import django.db.models.functions.text
6+
import netbox.models.deletion
7+
import re
8+
import taggit.managers
9+
import utilities.json
10+
import utilities.validators
11+
from django.db import migrations, models
12+
13+
14+
class Migration(migrations.Migration):
15+
16+
initial = True
17+
18+
dependencies = [
19+
("core", "0018_concrete_objecttype"),
20+
("extras", "0132_configcontextprofile"),
21+
]
22+
23+
operations = [
24+
migrations.CreateModel(
25+
name="CustomObjectObjectType",
26+
fields=[],
27+
options={
28+
"proxy": True,
29+
"indexes": [],
30+
"constraints": [],
31+
},
32+
bases=("core.objecttype",),
33+
),
34+
migrations.CreateModel(
35+
name="CustomObjectType",
36+
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+
("name", models.CharField(max_length=100, unique=True)),
56+
("schema", models.JSONField(blank=True, default=dict)),
57+
("verbose_name_plural", models.CharField(blank=True, max_length=100)),
58+
(
59+
"tags",
60+
taggit.managers.TaggableManager(
61+
through="extras.TaggedItem", to="extras.Tag"
62+
),
63+
),
64+
],
65+
options={
66+
"verbose_name": "Custom Object Type",
67+
"ordering": ("name",),
68+
},
69+
bases=(netbox.models.deletion.DeleteMixin, models.Model),
70+
),
71+
migrations.CreateModel(
72+
name="CustomObjectTypeField",
73+
fields=[
74+
(
75+
"id",
76+
models.BigAutoField(
77+
auto_created=True, primary_key=True, serialize=False
78+
),
79+
),
80+
("created", models.DateTimeField(auto_now_add=True, null=True)),
81+
("last_updated", models.DateTimeField(auto_now=True, null=True)),
82+
("type", models.CharField(default="text", max_length=50)),
83+
("primary", models.BooleanField(default=False)),
84+
(
85+
"name",
86+
models.CharField(
87+
max_length=50,
88+
validators=[
89+
django.core.validators.RegexValidator(
90+
flags=re.RegexFlag["IGNORECASE"],
91+
message="Only alphanumeric characters and underscores are allowed.",
92+
regex="^[a-z0-9_]+$",
93+
),
94+
django.core.validators.RegexValidator(
95+
flags=re.RegexFlag["IGNORECASE"],
96+
inverse_match=True,
97+
message="Double underscores are not permitted in custom object field names.",
98+
regex="__",
99+
),
100+
],
101+
),
102+
),
103+
("label", models.CharField(blank=True, max_length=50)),
104+
("group_name", models.CharField(blank=True, max_length=50)),
105+
("description", models.CharField(blank=True, max_length=200)),
106+
("required", models.BooleanField(default=False)),
107+
("unique", models.BooleanField(default=False)),
108+
("search_weight", models.PositiveSmallIntegerField(default=500)),
109+
("filter_logic", models.CharField(default="loose", max_length=50)),
110+
("default", models.JSONField(blank=True, null=True)),
111+
("related_object_filter", models.JSONField(blank=True, null=True)),
112+
("weight", models.PositiveSmallIntegerField(default=100)),
113+
("validation_minimum", models.BigIntegerField(blank=True, null=True)),
114+
("validation_maximum", models.BigIntegerField(blank=True, null=True)),
115+
(
116+
"validation_regex",
117+
models.CharField(
118+
blank=True,
119+
max_length=500,
120+
validators=[utilities.validators.validate_regex],
121+
),
122+
),
123+
("ui_visible", models.CharField(default="always", max_length=50)),
124+
("ui_editable", models.CharField(default="yes", max_length=50)),
125+
("is_cloneable", models.BooleanField(default=False)),
126+
("comments", models.TextField(blank=True)),
127+
(
128+
"choice_set",
129+
models.ForeignKey(
130+
blank=True,
131+
null=True,
132+
on_delete=django.db.models.deletion.PROTECT,
133+
related_name="choices_for_object_type",
134+
to="extras.customfieldchoiceset",
135+
),
136+
),
137+
(
138+
"custom_object_type",
139+
models.ForeignKey(
140+
on_delete=django.db.models.deletion.CASCADE,
141+
related_name="fields",
142+
to="netbox_custom_objects.customobjecttype",
143+
),
144+
),
145+
(
146+
"related_object_type",
147+
models.ForeignKey(
148+
blank=True,
149+
null=True,
150+
on_delete=django.db.models.deletion.PROTECT,
151+
to="core.objecttype",
152+
),
153+
),
154+
],
155+
options={
156+
"verbose_name": "custom object type field",
157+
"verbose_name_plural": "custom object type fields",
158+
"ordering": ["group_name", "weight", "name"],
159+
},
160+
bases=(netbox.models.deletion.DeleteMixin, models.Model),
161+
),
162+
migrations.AddConstraint(
163+
model_name="customobjecttype",
164+
constraint=models.UniqueConstraint(
165+
django.db.models.functions.text.Lower("name"),
166+
name="netbox_custom_objects_customobjecttype_name",
167+
violation_error_message="A Custom Object Type with this name already exists.",
168+
),
169+
),
170+
migrations.AddConstraint(
171+
model_name="customobjecttypefield",
172+
constraint=models.UniqueConstraint(
173+
fields=("name", "custom_object_type"),
174+
name="netbox_custom_objects_customobjecttypefield_unique_name",
175+
),
176+
),
177+
]

0 commit comments

Comments
 (0)