Opened 12 years ago
Closed 12 years ago
#19049 closed Bug (fixed)
Subclassing AbstractUser doesn't work
Reported by: | Ivan Virabyan | Owned by: | nobody |
---|---|---|---|
Component: | contrib.auth | Version: | dev |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
According to https://docs.djangoproject.com/en/dev/topics/auth/#extending-django-s-default-user I created my own User model
from django.contrib.auth.models import AbstractUser class User(AbstractUser): avatar = models.ImageField(upload_to='avatars')
but django complains:
CommandError: One or more models did not validate: accounts.user: Accessor for m2m field 'groups' clashes with related m2m field 'Group.user_set'. Add a related_name argument to the definition for 'groups'. accounts.user: Accessor for m2m field 'user_permissions' clashes with related m2m field 'Permission.user_set'. Add a related_name argument to the definition for 'user_permissions'. auth.user: Accessor for m2m field 'groups' clashes with related m2m field 'Group.user_set'. Add a related_name argument to the definition for 'groups'. auth.user: Accessor for m2m field 'user_permissions' clashes with related m2m field 'Permission.user_set'. Add a related_name argument to the definition for 'user_permissions'.
Change History (9)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:4 by , 12 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
Nevertheless, django still complains. It only works if I rename my model to CustomUser
or something.
comment:5 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|
this is because django.contrib.auth.models.User and group are being installed as loaded models, and reverse relations are being set to Django's default 'User' model, and reserving the user_set etc reverse relations
comment:6 by , 12 years ago
Severity: | Normal → Release blocker |
---|
This will need to be fixed before release; banning "User" as a model name is a pretty big failing, and there's also the possibility that stray reverse relations are being installed.
comment:7 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
comment:8 by , 12 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
while this fixes the auth tests - it badly blows up everything else it seems
http://ci.djangoproject.com/job/Django/database=sqlite3,python=python2.7/1763/
comment:9 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Do you have settings.AUTH_USER_MODEL set to your User model? It seems you have both auth.user and accounts.user installed... I don't think it is possible to have subclassed AbstractUser in use in addition to the default User model.