Introduction
The DRF Queryset Mixin is a utility for optimizing database queries in Django REST Framework (DRF) viewsets. It provides a mixin called QuerysetMixin that allows you to easily optimize your queries by specifying deferred, selected related, and prefetched related fields.
Installation
pip install drf-queryset
Usage
Please follow the steps:
- Import the
QuerysetMixinfromdrf_queryset.mixins. - In your viewset class, inherit from
QuerysetMixin. only_fields: List of fields to be only fetched in the query.defer_fields: List of fields to be deferred in the query.select_related_fields: List of fields to be select_related in the query.prefetch_related_fields: List of fields to be prefetch_related in the query.
Note: These fields are optional, you can use them depending upon your requirements of queryset and structure of the model fields.
Example
Here's a basic example of how you can use this package in your django rest framework application:
from drf_queryset.mixins import QuerysetMixin
from rest_framework.viewsets import ModelViewSet
from .models import YourModel
from .serializers import YourSerializer
class MyViewSet(QuerysetMixin, ModelViewSet):
queryset = YourModel.objects.all() # Replace with your queryset
serializer_class = YourSerializer # Replace with your serializer
defer_fields = ['field1', 'field2'] # Add your defer fields here
only_fields = ['field3', 'field4'] # Add your only fields here
select_related_fields = ['related_field1', 'related_field2'] # Add your select_related fields here
prefetch_related_fields = ['m2m_field', 'reverse_fk_field'] # Add your prefetch_related fields here
License
MIT License
Metadata
Release files for drf-queryset 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| drf-queryset-0.1.0.tar.gz | 3.0 kB | Without provenance | Details for drf-queryset-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| drf_queryset-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for drf_queryset-0.1.0-py3-none-any.whl |
Total release size: 6.4 kB
Release files / drf-queryset-0.1.0.tar.gz
| Download URL | drf-queryset-0.1.0.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ef6c5f540fbba8fb2952b495805c47f122647f58b8b0785219bf8883f4e8e5c4
|
|
BLAKE2b-256 checksum How to use checksums |
b251ad76585792169db30a88912e85b65039d8fa502f8a74a7bbd6a776447a77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.6
|
Release files / drf_queryset-0.1.0-py3-none-any.whl
| Download URL | drf_queryset-0.1.0-py3-none-any.whl |
|---|---|
| Size | 3.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a5265ebb7456433ac77a57ba86e29d8ba42c94a9da63842229ac0d47534e1c51
|
|
BLAKE2b-256 checksum How to use checksums |
1e99d1719418ea5603e8d01aff4001bd19e0302e5e0cab03a7c8fb50f2a73ae1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.6
|
Security for drf-queryset 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.