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 hashes)

Uploaded Source

Built Distribution

drf_queryset_optimization-0.1.1-py3-none-any.whl (2.5 kB view hashes)

Uploaded Python 3

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