35👍
✅
You need to assign a User object e.g.
from django.contrib.auth.models import User
user = User.objects.get(id=user_id)
staffprofile.user = user
5👍
user
needs to be an instance of the User
model, not a unicode object (which is what you are passing it).
- [Django]-Django: How to get current user in admin forms?
- [Django]-How to disable Django's CSRF validation?
- [Django]-Django REST Framework (DRF): TypeError: register() got an unexpected keyword argument 'base_name'
0👍
Yes you have to pass User instance in staffprofile.user = user_id
user id place.
As @david-s pointed out in a comment, if you don’t have a user instance, you have to fetch from DB with an additional query.
Instead you can directly do is
staffprofile.user_id = user_id
because Django behind the scene append _id
in table for foreign keys so staffprofile.user
will end staffprofile.user_id
- [Django]-Django rest framework create nested objects "Models" by POST
- [Django]-Giving email account a name when sending emails with Django through Google Apps
- [Django]-Name duplicates previous WSGI daemon definition
Source:stackexchange.com