[Django]-Access to fields of prefetch_related on reverse relation

6👍

You can get it from owner_set:

[owner.name for dog in dogs for owner in dog.owner_set.all()]

Unlike select_related(), prefetch_related() precaches data from related objects, so this won’t hit the database each time we need an owner_set per dog – see docs.

👤alecxe

Leave a comment