Skip to main content

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:

  1. Import the QuerysetOptimizationMixin from drf_queryset_optimization.mixins.

  2. In your viewset class, inherit from QuerysetOptimizationMixin.

  3. Specify the fields you want to defer or include using the defer_fields and only_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


Download files

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

Source Distribution

drf-queryset-optimization-0.1.1.tar.gz (2.1 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file drf-queryset-optimization-0.1.1.tar.gz.

File metadata

File hashes

Hashes for drf-queryset-optimization-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7b10f14b1165ff1fbd989c24f49318d01da0e2f2ccb42a94b795de53d0720646
MD5 c67ccd383af967c810f4657677b67d36
BLAKE2b-256 fb609e8873898ec2d2c2e20647e385afc55ca784fb0f1092630a49dac6852ee1

See more details on using hashes here.

File details

Details for the file drf_queryset_optimization-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for drf_queryset_optimization-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ba12dce73820ae19c00216ee16eb6bb4d6f56c1e64b74c266221983962095298
MD5 7a566b7931233cc51e2a792a92208db8
BLAKE2b-256 b84015db2c18a2d26e2c765590bb098e8b962fc6f47e45db3529606ccd44bd47

See more details on using hashes here.

Supported by

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