Просмотр исходного кода

Closes #8451: Include ChangeLoggingMixin in BaseModel

jeremystretch 4 лет назад
Родитель
Сommit
a795b95f7e
3 измененных файлов с 7 добавлено и 7 удалено
  1. 3 0
      docs/plugins/development/models.md
  2. 4 3
      netbox/netbox/models/__init__.py
  3. 0 4
      netbox/netbox/models/features.py

+ 3 - 0
docs/plugins/development/models.md

@@ -47,6 +47,7 @@ For more background on schema migrations, see the [Django documentation](https:/
 
 
 Plugin models can leverage certain NetBox features by inheriting from NetBox's `BaseModel` class. This class extends the plugin model to enable numerous feature, including:
 Plugin models can leverage certain NetBox features by inheriting from NetBox's `BaseModel` class. This class extends the plugin model to enable numerous feature, including:
 
 
+* Change logging
 * Custom fields
 * Custom fields
 * Custom links
 * Custom links
 * Custom validation
 * Custom validation
@@ -92,6 +93,8 @@ The example above will enable export templates and tags, but no other NetBox fea
 !!! note
 !!! note
     Please note that only the classes which appear in this documentation are currently supported. Although other classes may be present within the `features` module, they are not yet supported for use by plugins.
     Please note that only the classes which appear in this documentation are currently supported. Although other classes may be present within the `features` module, they are not yet supported for use by plugins.
 
 
+::: netbox.models.features.ChangeLoggingMixin
+
 ::: netbox.models.features.CustomLinksMixin
 ::: netbox.models.features.CustomLinksMixin
 
 
 ::: netbox.models.features.CustomFieldsMixin
 ::: netbox.models.features.CustomFieldsMixin

+ 4 - 3
netbox/netbox/models/__init__.py

@@ -19,6 +19,7 @@ __all__ = (
 #
 #
 
 
 class BaseModel(
 class BaseModel(
+    ChangeLoggingMixin,
     CustomFieldsMixin,
     CustomFieldsMixin,
     CustomLinksMixin,
     CustomLinksMixin,
     CustomValidationMixin,
     CustomValidationMixin,
@@ -41,7 +42,7 @@ class ChangeLoggedModel(ChangeLoggingMixin, CustomValidationMixin, models.Model)
         abstract = True
         abstract = True
 
 
 
 
-class PrimaryModel(BaseModel, ChangeLoggingMixin, models.Model):
+class PrimaryModel(BaseModel, models.Model):
     """
     """
     Primary models represent real objects within the infrastructure being modeled.
     Primary models represent real objects within the infrastructure being modeled.
     """
     """
@@ -51,7 +52,7 @@ class PrimaryModel(BaseModel, ChangeLoggingMixin, models.Model):
         abstract = True
         abstract = True
 
 
 
 
-class NestedGroupModel(BaseModel, ChangeLoggingMixin, MPTTModel):
+class NestedGroupModel(BaseModel, MPTTModel):
     """
     """
     Base model for objects which are used to form a hierarchy (regions, locations, etc.). These models nest
     Base model for objects which are used to form a hierarchy (regions, locations, etc.). These models nest
     recursively using MPTT. Within each parent, each child instance must have a unique name.
     recursively using MPTT. Within each parent, each child instance must have a unique name.
@@ -93,7 +94,7 @@ class NestedGroupModel(BaseModel, ChangeLoggingMixin, MPTTModel):
             })
             })
 
 
 
 
-class OrganizationalModel(BaseModel, ChangeLoggingMixin, models.Model):
+class OrganizationalModel(BaseModel, models.Model):
     """
     """
     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

+ 0 - 4
netbox/netbox/models/features.py

@@ -1,5 +1,3 @@
-import logging
-
 from django.contrib.contenttypes.fields import GenericRelation
 from django.contrib.contenttypes.fields import GenericRelation
 from django.db.models.signals import class_prepared
 from django.db.models.signals import class_prepared
 from django.dispatch import receiver
 from django.dispatch import receiver
@@ -53,8 +51,6 @@ class ChangeLoggingMixin(models.Model):
         """
         """
         Save a snapshot of the object's current state in preparation for modification.
         Save a snapshot of the object's current state in preparation for modification.
         """
         """
-        logger = logging.getLogger('netbox')
-        logger.debug(f"Taking a snapshot of {self}")
         self._prechange_snapshot = serialize_object(self)
         self._prechange_snapshot = serialize_object(self)
 
 
     def to_objectchange(self, action):
     def to_objectchange(self, action):