1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Standardize model types based on function

This commit is contained in:
Jeremy Stretch
2021-02-24 21:01:16 -05:00
parent 0a6ebdee48
commit bec7ea7072
31 changed files with 1569 additions and 579 deletions

View File

@@ -4,48 +4,12 @@ from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.urls import reverse
from utilities.querysets import RestrictedQuerySet
from utilities.utils import serialize_object
from extras.choices import *
from netbox.models import BigIDModel
from utilities.querysets import RestrictedQuerySet
#
# Change logging
#
class ChangeLoggedModel(models.Model):
"""
An abstract model which adds fields to store the creation and last-updated times for an object. Both fields can be
null to facilitate adding these fields to existing instances via a database migration.
"""
created = models.DateField(
auto_now_add=True,
blank=True,
null=True
)
last_updated = models.DateTimeField(
auto_now=True,
blank=True,
null=True
)
class Meta:
abstract = True
def to_objectchange(self, action):
"""
Return a new ObjectChange representing a change made to this object. This will typically be called automatically
by ChangeLoggingMiddleware.
"""
return ObjectChange(
changed_object=self,
object_repr=str(self),
action=action,
object_data=serialize_object(self)
)
class ObjectChange(models.Model):
class ObjectChange(BigIDModel):
"""
Record a change to an object and the user account associated with that change. A change record may optionally
indicate an object related to the one being changed. For example, a change to an interface may also indicate the