I have recently switched to Djoser for my authentication service in my DRF api.
I have a slightly tweaked User model where the PK has changed from id to user_id.
When I call /auth/users/me/ I get the following error:
django.core.exceptions.FieldError: Cannot resolve keyword 'id' into field. Choices are: date_joined, email, first_name, groups, user_id etc..
This is my current Djoser settings:
DJOSER = {
'USER_ID_FIELD': 'user_id',
'LOGIN_FIELD': 'email',
'USER_CREATE_PASSWORD_RETYPE': True,
'USERNAME_CHANGED_EMAIL_CONFIRMATION': True,
'PASSWORD_CHANGED_EMAIL_CONFIRMATION': True,
'SEND_CONFIRMATION_EMAIL': True,
'PASSWORD_RESET_CONFIRM_URL': 'password/reset/confirm/{uid}/{token}',
'USERNAME_RESET_CONFIRM_URL': 'email/reset/confirm/{uid}/{token}',
'ACTIVATION_URL': 'activate/{uid}/{token}',
'SEND_ACTIVATION_EMAIL': True,
'SERIALIZERS': {
'user_create': 'bb.serializers.RegisterSerializer',
'user_delete': 'djoser.serializers.UserDeleteSerializer'
},
}
What can I do to change the target primary key to point at user_id?
Ideally I wouldn't have to change the name of the field to id as I am using this field a lot across the project.
Any help would be greatly appreciated.
Extended User Model:
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
user_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
is_connected = models.BooleanField(
_('Connected'),
default=False,
)
class Meta:
db_table = 'bb_user'