[Answered ]-Accessing objects from another model using foreign key

2👍

You can use the double underscore notation to get related fields in a single call. Try this instead:

Points.objects.filter(user_id=id)
              .values_list('user_id', 'lat', 'lon', 'user_id__username')

(Though you should rename user_id to user. Django appends _id to your foreign key fields, which means that you now have two attributes: user_id, which will evaluate to the User object, and user_id_id, which will evaluate to the numerical id.)

Leave a comment