Skip to content

Commit 89286a7

Browse files
committed
NPL-386 fix up journal entry
1 parent aee5a38 commit 89286a7

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Generated by Django 5.2.4 on 2025-08-06 16:45
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("netbox_custom_objects", "0005_alter_customobjecttype_description"),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name="CustomObjectBase",
16+
fields=[
17+
(
18+
"id",
19+
models.BigAutoField(
20+
auto_created=True, primary_key=True, serialize=False
21+
),
22+
),
23+
(
24+
"custom_object_type",
25+
models.ForeignKey(
26+
blank=True,
27+
editable=False,
28+
null=True,
29+
on_delete=django.db.models.deletion.CASCADE,
30+
to="netbox_custom_objects.customobjecttype",
31+
),
32+
),
33+
],
34+
),
35+
]

netbox_custom_objects/models.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@
5252
USER_TABLE_DATABASE_NAME_PREFIX = "custom_objects_"
5353

5454

55+
class CustomObjectBase(models.Model):
56+
"""
57+
Base class for all custom object models.
58+
"""
59+
custom_object_type = models.ForeignKey(
60+
'CustomObjectType', on_delete=models.CASCADE, editable=False, null=True, blank=True
61+
)
62+
63+
5564
class CustomObject(
5665
BookmarksMixin,
5766
ChangeLoggingMixin,
@@ -134,6 +143,10 @@ def get_list_url(self):
134143
kwargs={"custom_object_type": self.custom_object_type.name.lower()},
135144
)
136145

146+
@classmethod
147+
def _get_viewname(cls, action=None, rest_api=False):
148+
return f"plugins:netbox_custom_objects:customobject_{action}"
149+
137150

138151
class CustomObjectType(PrimaryModel):
139152
# Class-level cache for generated models
@@ -403,8 +416,6 @@ def get_model(
403416
attrs = {
404417
"Meta": meta,
405418
"__module__": "database.models",
406-
"custom_object_type": self,
407-
"custom_object_type_id": self.id,
408419
}
409420

410421
field_attrs = self._fetch_and_generate_field_attrs(fields)
@@ -428,9 +439,10 @@ def wrapped_post_through_setup(self, cls):
428439
try:
429440
model = type(
430441
str(model_name),
431-
(CustomObject, models.Model),
442+
(CustomObject, CustomObjectBase),
432443
attrs,
433444
)
445+
model.custom_object_type = self
434446
finally:
435447
# Restore the original method
436448
TM.post_through_setup = original_post_through_setup

netbox_custom_objects/tables.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,15 @@ class Meta(NetBoxTable.Meta):
178178
"pk",
179179
"id",
180180
"name",
181-
"custom_object_type",
181+
# "custom_object_type",
182182
"created",
183183
"last_updated",
184184
)
185185
default_columns = (
186186
"pk",
187187
"id",
188188
"name",
189-
"custom_object_type",
189+
# "custom_object_type",
190190
"created",
191191
"last_updated",
192192
)

netbox_custom_objects/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
name="customobject_delete",
6666
),
6767
path(
68-
"<str:custom_object_type>/<int:pk>/journal/",
68+
"custom_object/<int:pk>/journal/",
6969
views.CustomObjectJournalView.as_view(),
7070
name="customobject_journal",
7171
),

0 commit comments

Comments
 (0)