I'm using the django admin and want to sort (by last_name) the dropdown list of users in a related field (ForeignKey).
I'm am using the standard User model in django. I tried the following in the model.py which is not working:
...
from django.contrib.auth.models import User
class Meta:
ordering = ['last_name']
User.add_to_class("Meta", Meta)
...
class Application(models.Model):
...
user = models.ForeignKey(User,
verbose_name="xyz",
null=True, blank=True,
limit_choices_to={'is_active': True},
on_delete=models.PROTECT)
...
Why is this not working? Is there another (easy) way to do it? I probably should have gone for a custom user model. But I didn't do that and changing it now is seams a lot of work.
I am using django 2.0.5 with python 3.6.5
Any help is appreciated.