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.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a20a9b2e9faf6cb4dd60c9c076a687fc67fdde56dead060428880879773a103d |
|
MD5 | 62ff506aa067e543452d082cbdb57e80 |
|
BLAKE2b-256 | 3a9201448528148d4d0fa7c3c922ac25aca80be57fd3a6ff477e319ec0befc97 |
Close
Hashes for django_auto_prefetching-0.1.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9686a9acccce59fc1ce00a2ce70b239f09a9c46479d5d9d47c10cdfbae7719bf |
|
MD5 | 688990df11a5466d4c09689a480270aa |
|
BLAKE2b-256 | 870dd5512e540d553cbf9965c38d6850a67a2761b257e51cb3dc3b89071bf954 |