Define a related name:
class Price(models.Model):
book = models.ForeignKey(Book, related_name="prices")
and then use it:
books = Book.objects.prefetch_related('prices')
More Related Contents:
- How to filter empty or NULL names in a QuerySet?
- Custom QuerySet and Manager without breaking DRY?
- Why does django’s prefetch_related() only work with all() and not filter()?
- Select DISTINCT individual columns in django?
- Raw SQL queries in Django views
- How to limit queryset/the records to view in Django admin site?
- Django: implementing JOIN using Django ORM?
- Django – filtering on foreign key properties
- Django query datetime for objects older than 5 hours
- django most efficient way to count same field values in a query
- Django Order By Date, but have “None” at end?
- how to write a query to get find value in a json field in django
- When saving, how can you check if a field has changed?
- How do I do an OR filter in a Django query?
- How to express a One-To-Many relationship in Django?
- Setting the selected value on a Django forms.ChoiceField
- Django: Set foreign key using integer?
- Django migrate –fake and –fake-initial explained
- django – get() returned more than one topic
- Django – how to specify a database for a model?
- “Post Image data using POSTMAN”
- Django model: delete() not triggered
- Django accessing ManyToMany fields from post_save signal
- Dropdown in Django Model
- How to query Case-insensitive data in Django ORM?
- Django comparing model instances for equality
- Get the latest record with filter in Django
- How to add Check Constraints for Django Model fields?
- Django queryset get exact manytomany lookup [duplicate]
- Django Migrations Add Field with Default as Function of Model