Giter Site home page Giter Site logo

hamzaijaz-dev / drf-queryset Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 3 KB

The DRF Queryset Mixin is a utility for optimizing database queries in Django REST Framework (DRF) viewsets.

License: MIT License

django django-project django-rest-framework drf optimization-tools python

drf-queryset's Introduction

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:

  1. Import the QuerysetMixin from drf_queryset.mixins.
  2. In your viewset class, inherit from QuerysetMixin.
  3. only_fields: List of fields to be only fetched in the query.
  4. defer_fields: List of fields to be deferred in the query.
  5. select_related_fields: List of fields to be select_related in the query.
  6. 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

drf-queryset's People

Contributors

hamzaijaz-dev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.