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

Extended primary models to include 'created' and 'last_updated' fields

This commit is contained in:
Jeremy Stretch
2016-06-22 10:19:00 -04:00
parent f42c0643e0
commit cb5991d5a6
8 changed files with 191 additions and 10 deletions

View File

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-06-22 14:10
from __future__ import unicode_literals
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('circuits', '0003_auto_20160621_1728'),
]
operations = [
migrations.AddField(
model_name='circuit',
name='created',
field=models.DateField(auto_now_add=True, default=datetime.date(2016, 6, 22)),
preserve_default=False,
),
migrations.AddField(
model_name='circuit',
name='last_updated',
field=models.DateTimeField(auto_now=True, default=datetime.datetime(2016, 6, 22, 14, 10, 28, 340517)),
preserve_default=False,
),
migrations.AddField(
model_name='provider',
name='created',
field=models.DateField(auto_now_add=True, default=datetime.date(2016, 6, 22)),
preserve_default=False,
),
migrations.AddField(
model_name='provider',
name='last_updated',
field=models.DateTimeField(auto_now=True, default=datetime.datetime(2016, 6, 22, 14, 10, 40, 964944)),
preserve_default=False,
),
]

View File

@ -2,9 +2,10 @@ from django.core.urlresolvers import reverse
from django.db import models
from dcim.models import Site, Interface
from utilities.models import CreatedUpdatedModel
class Provider(models.Model):
class Provider(CreatedUpdatedModel):
"""
Each Circuit belongs to a Provider. This is usually a telecommunications company or similar organization. This model
stores information pertinent to the user's relationship with the Provider.
@ -55,7 +56,7 @@ class CircuitType(models.Model):
return "{}?type={}".format(reverse('circuits:circuit_list'), self.slug)
class Circuit(models.Model):
class Circuit(CreatedUpdatedModel):
"""
A communications circuit connects two points. Each Circuit belongs to a Provider; Providers may have multiple
circuits. Each circuit is also assigned a CircuitType and a Site. A Circuit may be terminated to a specific device

View File

@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-06-22 14:08
from __future__ import unicode_literals
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dcim', '0008_auto_20160621_1843'),
]
operations = [
migrations.AddField(
model_name='device',
name='created',
field=models.DateField(auto_now_add=True, default=datetime.date(2016, 6, 22)),
preserve_default=False,
),
migrations.AddField(
model_name='device',
name='last_updated',
field=models.DateTimeField(auto_now=True, default=datetime.datetime(2016, 6, 22, 14, 7, 52, 775280)),
preserve_default=False,
),
migrations.AddField(
model_name='rack',
name='created',
field=models.DateField(auto_now_add=True, default=datetime.date(2016, 6, 22)),
preserve_default=False,
),
migrations.AddField(
model_name='rack',
name='last_updated',
field=models.DateTimeField(auto_now=True, default=datetime.datetime(2016, 6, 22, 14, 8, 27, 534709)),
preserve_default=False,
),
migrations.AddField(
model_name='site',
name='created',
field=models.DateField(auto_now_add=True, default=datetime.date(2016, 6, 22)),
preserve_default=False,
),
migrations.AddField(
model_name='site',
name='last_updated',
field=models.DateTimeField(auto_now=True, default=datetime.datetime(2016, 6, 22, 14, 8, 37, 622017)),
preserve_default=False,
),
]

View File

@ -8,6 +8,7 @@ from django.db.models import Q, ObjectDoesNotExist
from extras.rpc import RPC_CLIENTS
from utilities.fields import NullableCharField
from utilities.models import CreatedUpdatedModel
RACK_FACE_FRONT = 0
@ -82,7 +83,7 @@ RPC_CLIENT_CHOICES = [
]
class Site(models.Model):
class Site(CreatedUpdatedModel):
"""
A Site represents a geographic location within a network; typically a building or campus. The optional facility
field can be used to include an external designation, such as a data center name (e.g. Equinix SV6).
@ -157,7 +158,7 @@ class RackGroup(models.Model):
return "{}?group_id={}".format(reverse('dcim:rack_list'), self.pk)
class Rack(models.Model):
class Rack(CreatedUpdatedModel):
"""
Devices are housed within Racks. Each rack has a defined height measured in rack units, and a front and rear face.
Each Rack is assigned to a Site and (optionally) a RackGroup.
@ -456,7 +457,7 @@ class Platform(models.Model):
return "{}?platform={}".format(reverse('dcim:device_list'), self.slug)
class Device(models.Model):
class Device(CreatedUpdatedModel):
"""
A Device represents a piece of physical hardware mounted within a Rack. Each Device is assigned a DeviceType,
DeviceRole, and (optionally) a Platform. Device names are not required, however if one is set it must be unique.

View File

@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-06-22 14:13
from __future__ import unicode_literals
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ipam', '0005_delete_status'),
]
operations = [
migrations.AddField(
model_name='aggregate',
name='created',
field=models.DateField(auto_now_add=True, default=datetime.date(2016, 6, 22)),
preserve_default=False,
),
migrations.AddField(
model_name='aggregate',
name='last_updated',
field=models.DateTimeField(auto_now=True, default=datetime.datetime(2016, 6, 22, 14, 12, 29, 891569)),
preserve_default=False,
),
migrations.AddField(
model_name='ipaddress',
name='created',
field=models.DateField(auto_now_add=True, default=datetime.date(2016, 6, 22)),
preserve_default=False,
),
migrations.AddField(
model_name='ipaddress',
name='last_updated',
field=models.DateTimeField(auto_now=True, default=datetime.datetime(2016, 6, 22, 14, 12, 39, 666885)),
preserve_default=False,
),
migrations.AddField(
model_name='prefix',
name='created',
field=models.DateField(auto_now_add=True, default=datetime.date(2016, 6, 22)),
preserve_default=False,
),
migrations.AddField(
model_name='prefix',
name='last_updated',
field=models.DateTimeField(auto_now=True, default=datetime.datetime(2016, 6, 22, 14, 12, 48, 11411)),
preserve_default=False,
),
migrations.AddField(
model_name='vlan',
name='created',
field=models.DateField(auto_now_add=True, default=datetime.date(2016, 6, 22)),
preserve_default=False,
),
migrations.AddField(
model_name='vlan',
name='last_updated',
field=models.DateTimeField(auto_now=True, default=datetime.datetime(2016, 6, 22, 14, 12, 56, 963230)),
preserve_default=False,
),
migrations.AddField(
model_name='vrf',
name='created',
field=models.DateField(auto_now_add=True, default=datetime.date(2016, 6, 22)),
preserve_default=False,
),
migrations.AddField(
model_name='vrf',
name='last_updated',
field=models.DateTimeField(auto_now=True, default=datetime.datetime(2016, 6, 22, 14, 13, 4, 387113)),
preserve_default=False,
),
]

View File

@ -6,6 +6,7 @@ from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from dcim.models import Interface
from utilities.models import CreatedUpdatedModel
from .fields import IPNetworkField, IPAddressField
@ -36,7 +37,7 @@ STATUS_CHOICE_CLASSES = {
}
class VRF(models.Model):
class VRF(CreatedUpdatedModel):
"""
A virtual routing and forwarding (VRF) table represents a discrete layer three forwarding domain (e.g. a routing
table). Prefixes and IPAddresses can optionally be assigned to VRFs. (Prefixes and IPAddresses not assigned to a VRF
@ -85,7 +86,7 @@ class RIR(models.Model):
return "{}?rir={}".format(reverse('ipam:aggregate_list'), self.slug)
class Aggregate(models.Model):
class Aggregate(CreatedUpdatedModel):
"""
An aggregate exists at the root level of the IP address space hierarchy in NetBox. Aggregates are used to organize
the hierarchy and track the overall utilization of available address space. Each Aggregate is assigned to a RIR.
@ -206,7 +207,7 @@ class PrefixQuerySet(models.QuerySet):
return filter(lambda p: p.depth <= limit, queryset)
class Prefix(models.Model):
class Prefix(CreatedUpdatedModel):
"""
A Prefix represents an IPv4 or IPv6 network, including mask length. Prefixes can optionally be assigned to Sites and
VRFs. A Prefix must be assigned a status and may optionally be assigned a used-define Role. A Prefix can also be
@ -268,7 +269,7 @@ class Prefix(models.Model):
return STATUS_CHOICE_CLASSES[self.status]
class IPAddress(models.Model):
class IPAddress(CreatedUpdatedModel):
"""
An IPAddress represents an individual IPV4 or IPv6 address and its mask. The mask length should match what is
configured in the real world. (Typically, only loopback interfaces are configured with /32 or /128 masks.) Like
@ -323,7 +324,7 @@ class IPAddress(models.Model):
return None
class VLAN(models.Model):
class VLAN(CreatedUpdatedModel):
"""
A VLAN is a distinct layer two forwarding domain identified by a 12-bit integer (1-4094). Each VLAN must be assigned
to a Site, however VLAN IDs need not be unique within a Site. Like Prefixes, each VLAN is assigned an operational

View File

@ -11,6 +11,7 @@ from django.db import models
from django.utils.encoding import force_bytes
from dcim.models import Device
from utilities.models import CreatedUpdatedModel
from .hashers import SecretValidationHasher

View File

@ -0,0 +1,9 @@
from django.db import models
class CreatedUpdatedModel(models.Model):
created = models.DateField(auto_now_add=True)
last_updated = models.DateTimeField(auto_now=True)
class Meta:
abstract = True