|
|
@@ -2,7 +2,6 @@ from django.core.validators import ValidationError
|
|
|
from django.db import models
|
|
|
from mptt.models import MPTTModel, TreeForeignKey
|
|
|
|
|
|
-from extras.utils import is_taggable
|
|
|
from utilities.mptt import TreeManager
|
|
|
from utilities.querysets import RestrictedQuerySet
|
|
|
from netbox.models.features import *
|
|
|
@@ -32,7 +31,7 @@ class NetBoxFeatureSet(
|
|
|
def get_prerequisite_models(cls):
|
|
|
"""
|
|
|
Return a list of model types that are required to create this model or empty list if none. This is used for
|
|
|
- showing prequisite warnings in the UI on the list and detail views.
|
|
|
+ showing prerequisite warnings in the UI on the list and detail views.
|
|
|
"""
|
|
|
return []
|
|
|
|
|
|
@@ -52,7 +51,7 @@ class ChangeLoggedModel(ChangeLoggingMixin, CustomValidationMixin, models.Model)
|
|
|
abstract = True
|
|
|
|
|
|
|
|
|
-class NetBoxModel(NetBoxFeatureSet, models.Model):
|
|
|
+class NetBoxModel(CloningMixin, NetBoxFeatureSet, models.Model):
|
|
|
"""
|
|
|
Primary models represent real objects within the infrastructure being modeled.
|
|
|
"""
|
|
|
@@ -61,25 +60,6 @@ class NetBoxModel(NetBoxFeatureSet, models.Model):
|
|
|
class Meta:
|
|
|
abstract = True
|
|
|
|
|
|
- def clone(self):
|
|
|
- """
|
|
|
- Return a dictionary of attributes suitable for creating a copy of the current instance. This is used for pre-
|
|
|
- populating an object creation form in the UI.
|
|
|
- """
|
|
|
- attrs = {}
|
|
|
-
|
|
|
- for field_name in getattr(self, 'clone_fields', []):
|
|
|
- field = self._meta.get_field(field_name)
|
|
|
- field_value = field.value_from_object(self)
|
|
|
- if field_value not in (None, ''):
|
|
|
- attrs[field_name] = field_value
|
|
|
-
|
|
|
- # Include tags (if applicable)
|
|
|
- if is_taggable(self):
|
|
|
- attrs['tags'] = [tag.pk for tag in self.tags.all()]
|
|
|
-
|
|
|
- return attrs
|
|
|
-
|
|
|
|
|
|
class NestedGroupModel(NetBoxFeatureSet, MPTTModel):
|
|
|
"""
|