1👍
✅
You’re using filter
, which returns a list of all results, rather than get
, which returns only one:
active_user = MyProfile.objects.get(user=david)
The foreign key field is expecting an instance of MyProfile, not a list. Keep in mind this will raise a MyProfile.DoesNotExist
exception if no results are found.
This is about the same thing as filtering and just grabbing the first element:
active_user = MyProfile.objects.filter(user=david)[0]
# OR
active_user = MyProfile.objects.filter(user=david).first()
Source:stackexchange.com