Convert interface models to use NaturalOrderingField

This commit is contained in:
Jeremy Stretch
2020-02-07 15:47:53 -05:00
parent 9adeed55fb
commit 7c74d2ca65
5 changed files with 120 additions and 65 deletions

View File

@@ -4,9 +4,9 @@ from django.db import models
from dcim.choices import *
from dcim.constants import *
from dcim.managers import InterfaceManager
from extras.models import ObjectChange
from utilities.fields import NaturalOrderingField
from utilities.ordering import naturalize_interface
from utilities.utils import serialize_object
from .device_components import (
ConsolePort, ConsoleServerPort, DeviceBay, FrontPort, Interface, PowerOutlet, PowerPort, RearPort,
@@ -249,6 +249,12 @@ class InterfaceTemplate(ComponentTemplateModel):
name = models.CharField(
max_length=64
)
_name = NaturalOrderingField(
target_field='name',
naturalize_function=naturalize_interface,
max_length=100,
blank=True
)
type = models.CharField(
max_length=50,
choices=InterfaceTypeChoices
@@ -258,11 +264,9 @@ class InterfaceTemplate(ComponentTemplateModel):
verbose_name='Management only'
)
objects = InterfaceManager()
class Meta:
ordering = ['device_type', 'name']
unique_together = ['device_type', 'name']
ordering = ('device_type', '_name')
unique_together = ('device_type', 'name')
def __str__(self):
return self.name