Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_auto_prefetching-0.1.5.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_auto_prefetching-0.1.5-py2.py3-none-any.whl (18.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django_auto_prefetching-0.1.5.tar.gz.

File metadata

  • Download URL: django_auto_prefetching-0.1.5.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for django_auto_prefetching-0.1.5.tar.gz
Algorithm Hash digest
SHA256 f56794e5e378bcb68391457110a0b31bf8137273c41f6c59f8841a0115135a56
MD5 30ebef4229713ad6ecbd2a03b42efcaa
BLAKE2b-256 751a70f3f614c2c671c1a1d2e0ec4a85a43f26f7916eb2c110565dff0f8ba9af

See more details on using hashes here.

File details

Details for the file django_auto_prefetching-0.1.5-py2.py3-none-any.whl.

File metadata

  • Download URL: django_auto_prefetching-0.1.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for django_auto_prefetching-0.1.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e85626332b8ddfa92e050257e7219c3ea637d1a68b6708815e307e2f71dcbd1d
MD5 7c8822ef2b8e951cfe2431749d799394
BLAKE2b-256 caf6c139ec0ff8a799ac507c6af302e1ee86b14627cfb41d83580819d379feac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page