I have a project with one app, where user, their posts and other models are located. Now I want to separate User model and put it into different app, called users.
How should I do this correctly? And how do I use this model in the old app?
User model of the first app looks like this:
class User(AbstractUser):
class Meta:
permissions = (
('can_do_this', 'Permission1'),
('can_do_that', 'Permission2'),
...,
)
User model of the second (users)app looks like this:
class ExternalUser(AbstractUser):
class Meta:
permissions = (
('can_do_this', 'Permission1'),
('can_do_that', 'Permission2'),
...,
)
I've done django-admin startapp users
and copy-pasted user's model code into created app models.py.
Then I tried makemigrations
and it failed, showing:
SystemCheckError: System check identified some issues:
ERRORS:
photogal.User.groups: (fields.E304) Reverse accessor for 'User.groups'
clashes with reverse accessor for 'ExternalUser.groups'.
HINT: Add or change a related_name argument to the definition for
'User.groups' or 'ExternalUser.groups'.
photogal.User.user_permissions: (fields.E304) Reverse accessor for
'User.user_permissions' clashes with reverse accessor for
'ExternalUser.user_permissions'.
HINT: Add or change a related_name argument to the definition for
'User.user_permissions' or 'ExternalUser.user_permissions'.
users.ExternalUser.groups: (fields.E304) Reverse accessor for
'ExternalUser.groups' clashes with reverse accessor for 'User.groups'.
HINT: Add or change a related_name argument to the definition for
'ExternalUser.groups' or 'User.groups'.
users.ExternalUser.user_permissions: (fields.E304) Reverse accessor for
'ExternalUser.user_permissions' clashes with reverse accessor for
'User.user_permissions'.
HINT: Add or change a related_name argument to the definition for
'ExternalUser.user_permissions' or 'User.user_permissions'.
Adding related_name='+' to the old user model resulted in:
ERRORS:
<class 'django.contrib.auth.admin.UserAdmin'>: (admin.E020) The value of
'filter_horizontal[0]' must be a many-to-many field.
<class 'django.contrib.auth.admin.UserAdmin'>: (admin.E020) The value of
'filter_horizontal[1]' must be a many-to-many field.
Thanks!