Bladeren bron

Closes #20617: Introduce BaseModel

Jeremy Stretch 3 maanden geleden
bovenliggende
commit
77c08b7bf9
1 gewijzigde bestanden met toevoegingen van 26 en 15 verwijderingen
  1. 26 15
      netbox/netbox/models/__init__.py

+ 26 - 15
netbox/netbox/models/__init__.py

@@ -50,21 +50,15 @@ class NetBoxFeatureSet(
 # Base model classes
 # Base model classes
 #
 #
 
 
-class ChangeLoggedModel(ChangeLoggingMixin, CustomValidationMixin, EventRulesMixin, models.Model):
+class BaseModel(models.Model):
     """
     """
-    Base model for ancillary models; provides limited functionality for models which don't
-    support NetBox's full feature set.
-    """
-    objects = RestrictedQuerySet.as_manager()
-
-    class Meta:
-        abstract = True
-
+    A global base model for all NetBox objects.
 
 
-class NetBoxModel(NetBoxFeatureSet, models.Model):
-    """
-    Base model for most object types. Suitable for use by plugins.
+    This class provides some important overrides to Django's default functionality, such as
+    - Overriding the default manager to use RestrictedQuerySet
+    - Extending `clean()` to validate GenericForeignKey fields
     """
     """
+
     objects = RestrictedQuerySet.as_manager()
     objects = RestrictedQuerySet.as_manager()
 
 
     class Meta:
     class Meta:
@@ -103,6 +97,25 @@ class NetBoxModel(NetBoxFeatureSet, models.Model):
                     setattr(self, field.name, obj)
                     setattr(self, field.name, obj)
 
 
 
 
+class ChangeLoggedModel(ChangeLoggingMixin, CustomValidationMixin, EventRulesMixin, BaseModel):
+    """
+    Base model for ancillary models; provides limited functionality for models which don't
+    support NetBox's full feature set.
+    """
+
+    class Meta:
+        abstract = True
+
+
+class NetBoxModel(NetBoxFeatureSet, BaseModel):
+    """
+    Base model for most object types. Suitable for use by plugins.
+    """
+
+    class Meta:
+        abstract = True
+
+
 #
 #
 # NetBox internal base models
 # NetBox internal base models
 #
 #
@@ -177,7 +190,7 @@ class NestedGroupModel(NetBoxFeatureSet, MPTTModel):
             })
             })
 
 
 
 
-class OrganizationalModel(NetBoxFeatureSet, models.Model):
+class OrganizationalModel(NetBoxModel):
     """
     """
     Organizational models are those which are used solely to categorize and qualify other objects, and do not convey
     Organizational models are those which are used solely to categorize and qualify other objects, and do not convey
     any real information about the infrastructure being modeled (for example, functional device roles). Organizational
     any real information about the infrastructure being modeled (for example, functional device roles). Organizational
@@ -202,8 +215,6 @@ class OrganizationalModel(NetBoxFeatureSet, models.Model):
         blank=True
         blank=True
     )
     )
 
 
-    objects = RestrictedQuerySet.as_manager()
-
     class Meta:
     class Meta:
         abstract = True
         abstract = True
         ordering = ('name',)
         ordering = ('name',)