Skip to content

Commit 77c08b7

Browse files
committed
Closes #20617: Introduce BaseModel
1 parent adad7c2 commit 77c08b7

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

netbox/netbox/models/__init__.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,15 @@ def get_absolute_url(self):
5050
# Base model classes
5151
#
5252

53-
class ChangeLoggedModel(ChangeLoggingMixin, CustomValidationMixin, EventRulesMixin, models.Model):
53+
class BaseModel(models.Model):
5454
"""
55-
Base model for ancillary models; provides limited functionality for models which don't
56-
support NetBox's full feature set.
57-
"""
58-
objects = RestrictedQuerySet.as_manager()
59-
60-
class Meta:
61-
abstract = True
62-
55+
A global base model for all NetBox objects.
6356
64-
class NetBoxModel(NetBoxFeatureSet, models.Model):
65-
"""
66-
Base model for most object types. Suitable for use by plugins.
57+
This class provides some important overrides to Django's default functionality, such as
58+
- Overriding the default manager to use RestrictedQuerySet
59+
- Extending `clean()` to validate GenericForeignKey fields
6760
"""
61+
6862
objects = RestrictedQuerySet.as_manager()
6963

7064
class Meta:
@@ -103,6 +97,25 @@ def clean(self):
10397
setattr(self, field.name, obj)
10498

10599

100+
class ChangeLoggedModel(ChangeLoggingMixin, CustomValidationMixin, EventRulesMixin, BaseModel):
101+
"""
102+
Base model for ancillary models; provides limited functionality for models which don't
103+
support NetBox's full feature set.
104+
"""
105+
106+
class Meta:
107+
abstract = True
108+
109+
110+
class NetBoxModel(NetBoxFeatureSet, BaseModel):
111+
"""
112+
Base model for most object types. Suitable for use by plugins.
113+
"""
114+
115+
class Meta:
116+
abstract = True
117+
118+
106119
#
107120
# NetBox internal base models
108121
#
@@ -177,7 +190,7 @@ def clean(self):
177190
})
178191

179192

180-
class OrganizationalModel(NetBoxFeatureSet, models.Model):
193+
class OrganizationalModel(NetBoxModel):
181194
"""
182195
Organizational models are those which are used solely to categorize and qualify other objects, and do not convey
183196
any real information about the infrastructure being modeled (for example, functional device roles). Organizational
@@ -202,8 +215,6 @@ class OrganizationalModel(NetBoxFeatureSet, models.Model):
202215
blank=True
203216
)
204217

205-
objects = RestrictedQuerySet.as_manager()
206-
207218
class Meta:
208219
abstract = True
209220
ordering = ('name',)

0 commit comments

Comments
 (0)