[Fixed]-How to access a Django model instance after it has already been saved?

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()
👤Jessie

Leave a comment