diff --git a/docs/plugins/development/models.md b/docs/plugins/development/models.md index bf06faf08e..b8b1e31222 100644 --- a/docs/plugins/development/models.md +++ b/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: +* Change logging * Custom fields * Custom links * Custom validation @@ -92,6 +93,8 @@ The example above will enable export templates and tags, but no other NetBox fea !!! 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. +::: netbox.models.features.ChangeLoggingMixin + ::: netbox.models.features.CustomLinksMixin ::: netbox.models.features.CustomFieldsMixin diff --git a/netbox/netbox/models/__init__.py b/netbox/netbox/models/__init__.py index 638d27c1ba..bf120c8ac4 100644 --- a/netbox/netbox/models/__init__.py +++ b/netbox/netbox/models/__init__.py @@ -19,6 +19,7 @@ __all__ = ( # class BaseModel( + ChangeLoggingMixin, CustomFieldsMixin, CustomLinksMixin, CustomValidationMixin, @@ -41,7 +42,7 @@ class ChangeLoggedModel(ChangeLoggingMixin, CustomValidationMixin, models.Model) abstract = True -class PrimaryModel(BaseModel, ChangeLoggingMixin, models.Model): +class PrimaryModel(BaseModel, models.Model): """ Primary models represent real objects within the infrastructure being modeled. """ @@ -51,7 +52,7 @@ class PrimaryModel(BaseModel, ChangeLoggingMixin, models.Model): 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 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 any real information about the infrastructure being modeled (for example, functional device roles). Organizational diff --git a/netbox/netbox/models/features.py b/netbox/netbox/models/features.py index 19b804b01e..24b9a4bff5 100644 --- a/netbox/netbox/models/features.py +++ b/netbox/netbox/models/features.py @@ -1,5 +1,3 @@ -import logging - from django.contrib.contenttypes.fields import GenericRelation from django.db.models.signals import class_prepared 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. """ - logger = logging.getLogger('netbox') - logger.debug(f"Taking a snapshot of {self}") self._prechange_snapshot = serialize_object(self) def to_objectchange(self, action):