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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f571b64dd67a8c945c656059c13d5d5a95103a07d1cad7f4ccefe916e4036ac |
|
MD5 | 39d2669416e876c32981ad69b7c0c606 |
|
BLAKE2b-256 | 5b434b35339aa2f342f091bfaacd91a624f0762c6d6e89258c8cd21c95534804 |
Close
Hashes for django_auto_prefetching-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f391e74a7088ef643704f6fbce46ba7a4a17514ddd5437de00e390d33e78230c |
|
MD5 | e7fddb1047f50987f1a4834a45ea09a0 |
|
BLAKE2b-256 | c99a269d9cba851e4610a735110497e0e1d9bbed7a2d1d171ce31c41c3fd004b |