A package for optimizing querysets in Django REST Framework views and viewsets
Project description
drf-queryset-optimization
A Django package that provides mixins for optimizing querysets in Django REST Framework views and viewsets.
Features
- Defer specific fields in queryset using class attributes.
- Include only specific fields in queryset using class attributes.
Installation
pip install drf-queryset-optimization
Usage
Using the optimization mixins in your viewsets is straightforward:
-
Import the
QuerysetOptimizationMixinfromdrf_queryset_optimization.mixins. -
In your viewset class, inherit from
QuerysetOptimizationMixin. -
Specify the fields you want to defer or include using the
defer_fieldsandonly_fieldsclass attributes.
Example
Here's a basic example of how you can use the package in your project:
from drf_queryset_optimization.mixins import QuerysetOptimizationMixin
from rest_framework.viewsets import ModelViewSet
from .models import YourModel
from .serializers import YourSerializer
class OptimizedModelViewSet(QuerysetOptimizationMixin, ModelViewSet):
defer_fields = ["field1", "field2"] # Fields to defer
only_fields = [] # Fields to include
queryset = YourModel.objects.all()
serializer_class = YourSerializer
License
MIT License
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file drf-queryset-optimization-0.1.1.tar.gz.
File metadata
- Download URL: drf-queryset-optimization-0.1.1.tar.gz
- Upload date:
- Size: 2.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b10f14b1165ff1fbd989c24f49318d01da0e2f2ccb42a94b795de53d0720646
|
|
| MD5 |
c67ccd383af967c810f4657677b67d36
|
|
| BLAKE2b-256 |
fb609e8873898ec2d2c2e20647e385afc55ca784fb0f1092630a49dac6852ee1
|
File details
Details for the file drf_queryset_optimization-0.1.1-py3-none-any.whl.
File metadata
- Download URL: drf_queryset_optimization-0.1.1-py3-none-any.whl
- Upload date:
- Size: 2.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba12dce73820ae19c00216ee16eb6bb4d6f56c1e64b74c266221983962095298
|
|
| MD5 |
7a566b7931233cc51e2a792a92208db8
|
|
| BLAKE2b-256 |
b84015db2c18a2d26e2c765590bb098e8b962fc6f47e45db3529606ccd44bd47
|