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:
@@ -1,4 +1,4 @@
|
||||
from .change_logging import ChangeLoggedModel, ObjectChange
|
||||
from .change_logging import ObjectChange
|
||||
from .customfields import CustomField, CustomFieldModel
|
||||
from .models import (
|
||||
ConfigContext, ConfigContextModel, CustomLink, ExportTemplate, ImageAttachment, JobResult, Report, Script,
|
||||
@@ -7,7 +7,6 @@ from .models import (
|
||||
from .tags import Tag, TaggedItem
|
||||
|
||||
__all__ = (
|
||||
'ChangeLoggedModel',
|
||||
'ConfigContext',
|
||||
'ConfigContextModel',
|
||||
'CustomField',
|
||||
|
@@ -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
|
||||
|
@@ -12,12 +12,13 @@ from django.utils.safestring import mark_safe
|
||||
|
||||
from extras.choices import *
|
||||
from extras.utils import FeatureQuery
|
||||
from netbox.models import BigIDModel
|
||||
from utilities.forms import CSVChoiceField, DatePicker, LaxURLField, StaticSelect2, add_blank_choice
|
||||
from utilities.querysets import RestrictedQuerySet
|
||||
from utilities.validators import validate_regex
|
||||
|
||||
|
||||
class CustomFieldModel(models.Model):
|
||||
class CustomFieldModel(BigIDModel):
|
||||
"""
|
||||
Abstract class for any model which may have custom fields associated with it.
|
||||
"""
|
||||
@@ -77,7 +78,7 @@ class CustomFieldManager(models.Manager.from_queryset(RestrictedQuerySet)):
|
||||
return self.get_queryset().filter(content_types=content_type)
|
||||
|
||||
|
||||
class CustomField(models.Model):
|
||||
class CustomField(BigIDModel):
|
||||
content_types = models.ManyToManyField(
|
||||
to=ContentType,
|
||||
related_name='custom_fields',
|
||||
|
@@ -14,9 +14,9 @@ from rest_framework.utils.encoders import JSONEncoder
|
||||
|
||||
from extras.choices import *
|
||||
from extras.constants import *
|
||||
from extras.models import ChangeLoggedModel
|
||||
from extras.querysets import ConfigContextQuerySet
|
||||
from extras.utils import extras_features, FeatureQuery, image_upload
|
||||
from netbox.models import BigIDModel, PrimaryModel
|
||||
from utilities.querysets import RestrictedQuerySet
|
||||
from utilities.utils import deepmerge, render_jinja2
|
||||
|
||||
@@ -25,7 +25,7 @@ from utilities.utils import deepmerge, render_jinja2
|
||||
# Webhooks
|
||||
#
|
||||
|
||||
class Webhook(models.Model):
|
||||
class Webhook(BigIDModel):
|
||||
"""
|
||||
A Webhook defines a request that will be sent to a remote application when an object is created, updated, and/or
|
||||
delete in NetBox. The request will contain a representation of the object, which the remote application can act on.
|
||||
@@ -158,7 +158,7 @@ class Webhook(models.Model):
|
||||
# Custom links
|
||||
#
|
||||
|
||||
class CustomLink(models.Model):
|
||||
class CustomLink(BigIDModel):
|
||||
"""
|
||||
A custom link to an external representation of a NetBox object. The link text and URL fields accept Jinja2 template
|
||||
code to be rendered with an object as context.
|
||||
@@ -210,7 +210,7 @@ class CustomLink(models.Model):
|
||||
# Export templates
|
||||
#
|
||||
|
||||
class ExportTemplate(models.Model):
|
||||
class ExportTemplate(BigIDModel):
|
||||
content_type = models.ForeignKey(
|
||||
to=ContentType,
|
||||
on_delete=models.CASCADE,
|
||||
@@ -285,7 +285,7 @@ class ExportTemplate(models.Model):
|
||||
# Image attachments
|
||||
#
|
||||
|
||||
class ImageAttachment(models.Model):
|
||||
class ImageAttachment(BigIDModel):
|
||||
"""
|
||||
An uploaded image which is associated with an object.
|
||||
"""
|
||||
@@ -361,7 +361,7 @@ class ImageAttachment(models.Model):
|
||||
# Config contexts
|
||||
#
|
||||
|
||||
class ConfigContext(ChangeLoggedModel):
|
||||
class ConfigContext(PrimaryModel):
|
||||
"""
|
||||
A ConfigContext represents a set of arbitrary data available to any Device or VirtualMachine matching its assigned
|
||||
qualifiers (region, site, etc.). For example, the data stored in a ConfigContext assigned to site A and tenant B
|
||||
@@ -526,7 +526,7 @@ class Report(models.Model):
|
||||
# Job results
|
||||
#
|
||||
|
||||
class JobResult(models.Model):
|
||||
class JobResult(BigIDModel):
|
||||
"""
|
||||
This model stores the results from running a user-defined report.
|
||||
"""
|
||||
|
@@ -2,7 +2,7 @@ from django.db import models
|
||||
from django.utils.text import slugify
|
||||
from taggit.models import TagBase, GenericTaggedItemBase
|
||||
|
||||
from extras.models import ChangeLoggedModel
|
||||
from netbox.models import BigIDModel, CoreModel
|
||||
from utilities.choices import ColorChoices
|
||||
from utilities.fields import ColorField
|
||||
from utilities.querysets import RestrictedQuerySet
|
||||
@@ -12,7 +12,7 @@ from utilities.querysets import RestrictedQuerySet
|
||||
# Tags
|
||||
#
|
||||
|
||||
class Tag(TagBase, ChangeLoggedModel):
|
||||
class Tag(TagBase, CoreModel):
|
||||
color = ColorField(
|
||||
default=ColorChoices.COLOR_GREY
|
||||
)
|
||||
@@ -44,7 +44,7 @@ class Tag(TagBase, ChangeLoggedModel):
|
||||
)
|
||||
|
||||
|
||||
class TaggedItem(GenericTaggedItemBase):
|
||||
class TaggedItem(BigIDModel, GenericTaggedItemBase):
|
||||
tag = models.ForeignKey(
|
||||
to=Tag,
|
||||
related_name="%(app_label)s_%(class)s_items",
|
||||
|
Reference in New Issue
Block a user