I want to apply the ‘ordering’ Meta option to the Django model User from django.contrib.auth.models. Normally I would just put the Meta class in the model’s definition, but in this case I did not define the model. So where do I put the Meta class to modify the User model?
Share
Paolo’s answer is great; I wasn’t previously aware of the new proxy support. The only issue with it is that you need to target your code to the OrderedUser model – which is in a sense similar to simply doing a
User.objects.filter(....).order_by('username'). In other words, it’s less verbose but you need to explicitly write your code to target it. (Of course, as mentioned, you’d also have to be on trunk.)My sense is that you want all
Userqueries to be ordered, including in third party apps that you don’t control. In such a circumstance, monkeypatching the base class is relatively easy and very unlikely to cause any problems. In a central location (such as your settings.py), you could do:UPDATE: Django 1.5 now supports configurable User models.