Просмотр исходного кода

Closes #2131: Added created and last_updated fields to DeviceType

Jeremy Stretch 7 лет назад
Родитель
Сommit
8762f1314d

+ 1 - 1
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',
         ]
 
 

+ 12 - 0
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",

+ 27 - 0
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),
+        ),
+    ]

+ 1 - 1
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).

+ 1 - 2
netbox/templates/dcim/devicetype.html

@@ -11,7 +11,6 @@
         </ol>
     </div>
 </div>
-
 {% if perms.dcim.change_devicetype or perms.dcim.delete_devicetype %}
     <div class="pull-right">
       {% if perms.dcim.change_devicetype %}
@@ -28,8 +27,8 @@
       {% endif %}
     </div>
 {% endif %}
-
 <h1>{% block title %}{{ devicetype.manufacturer }} {{ devicetype.model }}{% endblock %}</h1>
+{% include 'inc/created_updated.html' with obj=devicetype %}
 <div class="row">
     <div class="col-md-5">
         <div class="panel panel-default">