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.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7bc0ac5994a4fd83948d2af54c106cb9bd07499413d02f998e39f6253759e67d |
|
MD5 | d3b1fb4e6a6cdd4f0e08b069a04f195e |
|
BLAKE2b-256 | 60ee800765d19a865b4413ced2fb91d5b6732064c2a31adda03925bd2ac8d5db |
Close
Hashes for django_auto_prefetching-0.1.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3794ffe588df4bbe8017640fa89f6ae0c0378e7631eef64f16562623ab39cbd |
|
MD5 | 11c9868a860803c309f6e23408638d5c |
|
BLAKE2b-256 | e1ad9e51a2035a578a1786108e0436b67ce4b31b75a1cede1f7b5319aa80b187 |