views:

47

answers:

1

I've inherited a Django application which uses a custom form-less auth backend. It works around the 30 character limit in django.contrib.auth.models.User by a SQL hack ALTER TABLE auth_user MODIFY COLUMN username varchar(90);, which is of course only valid for the database, but not for forms. Since I'm trying to remove all the hacks from code including SQL ones, I'm looking for a proper way to remove that limitation. How would you recommend removing it?

A: 

I can't think of any clean way to make such a change to the django.contrib.auth.models.User model. In fact almost any change is tricky.

One very flaky way would be to delegate the username to an UserProfile model. You can define an UserProfile model that has a one-to-one relationship with User. You'll then have to add a field to the profile model to hold the longer-than-usual username.

It doesn't end there. To make things seamless you'll have to write custom managers to make sure that the username from the profile field is used when querying for users.

Now that I have spelled it out I don't like the above method at all. Needless to say it is untested.

Manoj Govindan