Tools for automatically prefetching related objects in Django and Django-rest-framework
Project description
Django auto-prefetching
NOTICE: THIS PROJECT IS A WORK IN PROGRESS, AND IS NOT PUBLISHED TO PYPI YET
Automatic prefetching of related objects for Django Rest Framework.
Inside your ViewSets get_queryset
add the following code:
def get_queryset():
qs = YOUR_MODEL.objects.all() # Or whatever queryset you want to use
qs = prefetch(self.get_serializer_class(), queryset) # This line prefetches the related model depending on the serializer.
return qs
Unresolved issues
- If you forget to add
many=True
to a serializer that has the reverse side of the ForeignKey we calculate the wrong prefetch_related fields and we get an error. We can't catch this error early because it's only thrown when the queryset is evaluated - We can't prefetch anything that's accessed in serializer method fields.
LICENSE:
MIT
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
Built Distribution
Close
Hashes for django_auto_prefetching-0.1.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f56794e5e378bcb68391457110a0b31bf8137273c41f6c59f8841a0115135a56 |
|
MD5 | 30ebef4229713ad6ecbd2a03b42efcaa |
|
BLAKE2b-256 | 751a70f3f614c2c671c1a1d2e0ec4a85a43f26f7916eb2c110565dff0f8ba9af |
Close
Hashes for django_auto_prefetching-0.1.5-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e85626332b8ddfa92e050257e7219c3ea637d1a68b6708815e307e2f71dcbd1d |
|
MD5 | 7c8822ef2b8e951cfe2431749d799394 |
|
BLAKE2b-256 | caf6c139ec0ff8a799ac507c6af302e1ee86b14627cfb41d83580819d379feac |