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
QuerysetOptimizationMixin
fromdrf_queryset_optimization.mixins
. -
In your viewset class, inherit from
QuerysetOptimizationMixin
. -
Specify the fields you want to defer or include using the
defer_fields
andonly_fields
class 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
Close
Hashes for drf-queryset-optimization-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b10f14b1165ff1fbd989c24f49318d01da0e2f2ccb42a94b795de53d0720646 |
|
MD5 | c67ccd383af967c810f4657677b67d36 |
|
BLAKE2b-256 | fb609e8873898ec2d2c2e20647e385afc55ca784fb0f1092630a49dac6852ee1 |
Close
Hashes for drf_queryset_optimization-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba12dce73820ae19c00216ee16eb6bb4d6f56c1e64b74c266221983962095298 |
|
MD5 | 7a566b7931233cc51e2a792a92208db8 |
|
BLAKE2b-256 | b84015db2c18a2d26e2c765590bb098e8b962fc6f47e45db3529606ccd44bd47 |