An library of utilities and enhancements for Django's prefetch_related system.
This library currently provides a replacement implementation of prefetch_related_objects which uses an identity map to automatically reduce the number of queries performed when prefetching.
For example, considered the following data model:
class Toy(models.Model): dog = models.ForeignKey('dogs.Dog') class Dog(models.Model): name = models.CharField() favorite_toy = models.ForeignKey('toys.Toy', null=True)
With this library, we get don’t need to do a database query to perform the prefetch for favorite_toy since that object had already been fetched as part of the prefetching for toy_set:
>>> dog = Dog.objects.prefetch_related('toys', 'favorite_toy') SELECT * from dogs_dog limit 1; SELECT * FROM toys_toy where toys_toy.dog_id IN (1); >>> dog.favorite_toy is dog.toy_set.all() # no queries done True
The plan is to increase the scope of the library in future versions to provide additional tools for working with prefetch_related.
- Free software: BSD 3-Clause License
pip install django-prefetch-utils
- First release on PyPI.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size django-prefetch-utils-0.1.0.tar.gz (51.6 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for django-prefetch-utils-0.1.0.tar.gz