How to override default user model field in Django?
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: 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 mod开发者_如何转开发els
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/...
)
There's this already asked... 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.
精彩评论