From 8762f1314d3fafb96b948790fc7c8d55b1280703 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 30 May 2018 13:41:14 -0400 Subject: [PATCH] Closes #2131: Added created and last_updated fields to DeviceType --- netbox/dcim/api/serializers.py | 2 +- netbox/dcim/fixtures/dcim.json | 12 +++++++++ ...59_devicetype_add_created_updated_times.py | 27 +++++++++++++++++++ netbox/dcim/models.py | 2 +- netbox/templates/dcim/devicetype.html | 3 +-- 5 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 netbox/dcim/migrations/0059_devicetype_add_created_updated_times.py diff --git a/netbox/dcim/api/serializers.py b/netbox/dcim/api/serializers.py index 763ea038c..8a8824138 100644 --- a/netbox/dcim/api/serializers.py +++ b/netbox/dcim/api/serializers.py @@ -234,7 +234,7 @@ class DeviceTypeSerializer(CustomFieldModelSerializer): fields = [ 'id', 'manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', 'interface_ordering', 'is_console_server', 'is_pdu', 'is_network_device', 'subdevice_role', 'comments', 'tags', 'custom_fields', - 'instance_count', + 'created', 'last_updated', 'instance_count', ] diff --git a/netbox/dcim/fixtures/dcim.json b/netbox/dcim/fixtures/dcim.json index 4a9eb15e4..761f1ba69 100644 --- a/netbox/dcim/fixtures/dcim.json +++ b/netbox/dcim/fixtures/dcim.json @@ -70,6 +70,8 @@ "model": "dcim.devicetype", "pk": 1, "fields": { + "created": "2016-06-23", + "last_updated": "2016-06-23T03:19:56.521Z", "manufacturer": 1, "model": "MX960", "slug": "mx960", @@ -84,6 +86,8 @@ "model": "dcim.devicetype", "pk": 2, "fields": { + "created": "2016-06-23", + "last_updated": "2016-06-23T03:19:56.521Z", "manufacturer": 1, "model": "EX9214", "slug": "ex9214", @@ -98,6 +102,8 @@ "model": "dcim.devicetype", "pk": 3, "fields": { + "created": "2016-06-23", + "last_updated": "2016-06-23T03:19:56.521Z", "manufacturer": 1, "model": "QFX5100-24Q", "slug": "qfx5100-24q", @@ -112,6 +118,8 @@ "model": "dcim.devicetype", "pk": 4, "fields": { + "created": "2016-06-23", + "last_updated": "2016-06-23T03:19:56.521Z", "manufacturer": 1, "model": "QFX5100-48S", "slug": "qfx5100-48s", @@ -126,6 +134,8 @@ "model": "dcim.devicetype", "pk": 5, "fields": { + "created": "2016-06-23", + "last_updated": "2016-06-23T03:19:56.521Z", "manufacturer": 2, "model": "CM4148", "slug": "cm4148", @@ -140,6 +150,8 @@ "model": "dcim.devicetype", "pk": 6, "fields": { + "created": "2016-06-23", + "last_updated": "2016-06-23T03:19:56.521Z", "manufacturer": 3, "model": "CWG-24VYM415C9", "slug": "cwg-24vym415c9", diff --git a/netbox/dcim/migrations/0059_devicetype_add_created_updated_times.py b/netbox/dcim/migrations/0059_devicetype_add_created_updated_times.py new file mode 100644 index 000000000..6a16656ed --- /dev/null +++ b/netbox/dcim/migrations/0059_devicetype_add_created_updated_times.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.12 on 2018-05-30 17:30 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('dcim', '0058_relax_rack_naming_constraints'), + ] + + operations = [ + migrations.AddField( + model_name='devicetype', + name='created', + field=models.DateField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='devicetype', + name='last_updated', + field=models.DateTimeField(auto_now=True), + ), + ] diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 19ba4a872..9fe1a9ef7 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -682,7 +682,7 @@ class Manufacturer(models.Model): @python_2_unicode_compatible -class DeviceType(models.Model, CustomFieldModel): +class DeviceType(CreatedUpdatedModel, CustomFieldModel): """ A DeviceType represents a particular make (Manufacturer) and model of device. It specifies rack height and depth, as well as high-level functional role(s). diff --git a/netbox/templates/dcim/devicetype.html b/netbox/templates/dcim/devicetype.html index 27d2e3694..25d33101e 100644 --- a/netbox/templates/dcim/devicetype.html +++ b/netbox/templates/dcim/devicetype.html @@ -11,7 +11,6 @@ - {% if perms.dcim.change_devicetype or perms.dcim.delete_devicetype %}
{% if perms.dcim.change_devicetype %} @@ -28,8 +27,8 @@ {% endif %}
{% endif %} -

{% block title %}{{ devicetype.manufacturer }} {{ devicetype.model }}{% endblock %}

+{% include 'inc/created_updated.html' with obj=devicetype %}