[Fixed]-Django – Access ForeignKey value without hitting database

20👍

You can do something like this:

pt_ids = Profile_Tag.objects.values_list('profile', flat=True)

This will return you list of IDs. For model instance, there’s another way:

pts = Profile_Tag.objects.all()
for pt in pts:
    print pt.profile_id

Leave a comment