Skip to content

Commit

Permalink
Fixes #14816: Ensure default contact assignment ordering is consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Jan 17, 2024
1 parent 621c3cc commit 5de2dea
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion netbox/tenancy/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 17 additions & 0 deletions netbox/tenancy/migrations/0014_contactassignment_ordering.py
Original file line number Diff line number Diff line change
@@ -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')},
),
]
2 changes: 1 addition & 1 deletion netbox/tenancy/models/contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
)
Expand Down
2 changes: 1 addition & 1 deletion netbox/tenancy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5de2dea

Please sign in to comment.