views:

336

answers:

1

The problem is the default User model does not have some very useful options given to the fields e.g unique=True to the email field.

I read this question: http://stackoverflow.com/questions/1817244/django-override-default-user-model-method, and checked Proxy Model concept, but with no effect.

At first I tried:

from django.contrib.auth import models
class User(models.User):
    class Meta:
        proxy = True
    email = EmailField('e-mail address', unique=True, blank=False)

which resulted in:

django.core.exceptions.FieldError: Proxy model 'User' contains model fields.

so next was:

from django.contrib.auth import models
class User(models.User):
    class Meta:
        proxy = True
    models.User.email = EmailField('e-mail address', unique=True, blank=False)

and this "solution" has no effect at all. Default User model was behaving the same as before.

I am interested in non-monkey-patching-solution only.

Edit: Ok. Monkey-patching is acceptable for me, but how make this reasonably? (I mean not changing the file that lies in /usr/pyshared/python2.6/...)

+1  A: 

There's this already asked... http://stackoverflow.com/questions/1160030/how-to-make-email-field-unique-in-model-user-from-contrib-auth-in-django

Also the django method of additional user data is here http://docs.djangoproject.com/en/dev/topics/auth/#auth-profiles .

I'm not entirely a fan of this method and appreciate where you are coming from, but sometimes you have to go with the herd.

michael
Thank You for Your response. First of all I am searching for a way to add to User model not only email field uniqueness validation. Solution of writing own form that check uniqueness of an email is that one I want to avoid (first link). Why? I think the better way is to add validation deeper. On the other hand, I can add email field to UserProfile model, but this doubles information in DB. *sigh* But I think I'll stick the form validation method.
Dejw