Is there an option in the django admin view for ordering of foreign key fields? i.e. I have a foreign key to a \"School\" model, which shows as a dropdown, sorted on pk-- I woul
The approved answer might override other changes on the queryset, so I prefer to use this because it's safer:
class StudentAdmin(admin.ModelAdmin):
def get_field_queryset(self, db, db_field, request):
queryset = super().get_field_queryset(db, db_field, request)
if db_field.name == 'school':
queryset = queryset.order_by('name')
return queryset