[Answer]-Python Django – Accessing foreignkey data

1👍

Use collection_detail_set to obtain a queryset of all collection_detail‘s with that collection.

If you want a one-to-one relationship instead of a one-to-many (which is what you get using ForeignKey), change

collection = models.ForeignKey(collection)

to

collection = models.OneToOneField(collection)

and access the collection‘s collection_detail simply by calling collection_detail from your collection model.

Leave a comment