An library of utilities and enhancements for Django's prefetch_related system.
Project description
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')[0] 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()[0] # 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
Installation
pip install django-prefetch-utils
Documentation
Changelog
0.1.0 (2019-07-16)
First release on PyPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for django-prefetch-utils-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 062be731dc47ef7350f41db85288905f472990135f2dee355d597f759f9a6e32 |
|
MD5 | 2e696f58966904f5f470dc891d87dc41 |
|
BLAKE2b-256 | 504c094a378fbef0a85b5f497869d01151f0e8c2e42fc6109a44484a0fdb676a |