diff --git a/netbox/tenancy/api/views.py b/netbox/tenancy/api/views.py index 71a4961c3a0..25c0ab40301 100644 --- a/netbox/tenancy/api/views.py +++ b/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 diff --git a/netbox/tenancy/migrations/0014_contactassignment_ordering.py b/netbox/tenancy/migrations/0014_contactassignment_ordering.py new file mode 100644 index 00000000000..66f08aa2a0f --- /dev/null +++ b/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')}, + ), + ] diff --git a/netbox/tenancy/models/contacts.py b/netbox/tenancy/models/contacts.py index 81e11a7dd13..664fff09841 100644 --- a/netbox/tenancy/models/contacts.py +++ b/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')), ) diff --git a/netbox/tenancy/views.py b/netbox/tenancy/views.py index 27d5750acf0..1d2fceb04ec 100644 --- a/netbox/tenancy/views.py +++ b/netbox/tenancy/views.py @@ -25,7 +25,7 @@ def get_children(self, request, parent): 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)