Posted: May 17th, 2010 | Author: Arif Harbott | Filed under: Django | Tags: auth models, meta | No Comments »
Following on from my last post on changing the behaviour of the Django contrib auth models. Another thing you might like to do is to change the default ordering:
from django.contrib.auth.models import User
User._meta.ordering = ['-email']
or
from django.contrib.auth.models import Group
Group._meta.ordering = ['-id']
Posted: April 29th, 2010 | Author: Arif Harbott | Filed under: Django | Tags: meta, model, models | No Comments »
Sometimes it can be helpful to change the default behaviour of the Auth User model or other models built into Django.
One use case might be if you want to change the length of the username field in the Auth User model to allow for longer usernames (e.g. an email address).
There is a simple way to change the max length attribute:
from django.contrib.auth.models import User
User._meta.get_field_by_name('username')[0].max_length=75