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

Fixes #14816: Ensure default contact assignment ordering is consistent

Jeremy Stretch 2 лет назад
Родитель
Сommit
5de2dea8a6

+ 1 - 1
netbox/tenancy/api/views.py

@@ -83,6 +83,6 @@ class ContactViewSet(NetBoxModelViewSet):
 
 
 class ContactAssignmentViewSet(NetBoxModelViewSet):
-    queryset = ContactAssignment.objects.prefetch_related('object', 'contact', 'role')
+    queryset = ContactAssignment.objects.prefetch_related('content_type', 'object', 'contact', 'role', 'tags')
     serializer_class = serializers.ContactAssignmentSerializer
     filterset_class = filtersets.ContactAssignmentFilterSet

+ 17 - 0
netbox/tenancy/migrations/0014_contactassignment_ordering.py

@@ -0,0 +1,17 @@
+# Generated by Django 4.2.8 on 2024-01-17 15:27
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('tenancy', '0013_gfk_indexes'),
+    ]
+
+    operations = [
+        migrations.AlterModelOptions(
+            name='contactassignment',
+            options={'ordering': ('contact', 'priority', 'role', 'pk')},
+        ),
+    ]

+ 1 - 1
netbox/tenancy/models/contacts.py

@@ -140,7 +140,7 @@ class ContactAssignment(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, Chan
     clone_fields = ('content_type', 'object_id', 'role', 'priority')
 
     class Meta:
-        ordering = ('priority', 'contact')
+        ordering = ('contact', 'priority', 'role', 'pk')
         indexes = (
             models.Index(fields=('content_type', 'object_id')),
         )

+ 1 - 1
netbox/tenancy/views.py

@@ -25,7 +25,7 @@ class ObjectContactsView(generic.ObjectChildrenView):
         return ContactAssignment.objects.restrict(request.user, 'view').filter(
             content_type=ContentType.objects.get_for_model(parent),
             object_id=parent.pk
-        )
+        ).order_by('priority', 'contact', 'role')
 
     def get_table(self, *args, **kwargs):
         table = super().get_table(*args, **kwargs)