No project description provided
Project description
Dj Easy view CRUD mixins
Makes your CRUD's even more smaller and customizable with dj easy views .
Installation
pip install djeasyview
Usage
GET and POST api's
This mixin provides generic implementations for listing and creating resources.
Example:
from djeasyview import DjeasyListCreateView
from your_app.models import YourModel
from your_app.serializers import YourModelSerializer
from rest_framework.permissions import IsAuthenticated
class YourView(DjeasyListCreateView):
model = YourModel
list_serializer_class = YourModelSerializer
create_serializer_class = YourModelSerializer
serializer_class = YourModelSerializer
queryset = YourModel
select_related = ['key1' , 'key2']
prefetch_related = ['key1' , 'key2']
permission_classes = [IsAuthenticated]
enable_cache = True
cache_duration = 60
query_params = {
"name": "name",
"related_field__id": "related_id",
"related_field__name": "related_name",
}
pagination = True
- with query params
e.g., localhost:8000/view/?name="anand"&related_id=1&related_name="anandraj"
- with pagination
e.g., localhost:8000/view/?page_size=10&page_number=1"
GET , PUT , PATCH , DELETE api's
This mixin provides generic implementations for Retrive , updating and deleting resources.
from djeasyview import DjeasyRetrieveUpdateApiView
from your_app.models import YourModel
from your_app.serializers import YourModelSerializer
from rest_framework.permissions import IsAuthenticated
class YourView(DjeasyRetrieveUpdateApiView):
model = YourModel
list_serializer_class = YourModelSerializer
create_serializer_class = YourModelSerializer
serializer_class = YourModelSerializer
queryset = YourModel
select_related = ['key1' , 'key2']
prefetch_related = ['key1' , 'key2']
permission_classes = [IsAuthenticated]
enable_cache = True
cache_duration = 60
Customization:
-
customize your get_queryset
def get_queryset(self): super().get_queryset() return YourModel.objects.filter(**filter_conditions)
-
customize your responses
from rest_framework.response import Response def get_response(self, serializer_klass, queryset): super().get_response(serializer_klass, self.get_queryset()) return Response(serializer_klass(queryset).data)
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
djeasyview-1.0.11.tar.gz
(4.8 kB
view hashes)
Built Distribution
Close
Hashes for djeasyview-1.0.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22510a5e411d3536d298ed6f4682c4d3f1407efde33b2147466bfbfad8f1fb63 |
|
MD5 | a3a9a4e651946281a0c94fad6dd46c3c |
|
BLAKE2b-256 | 988cea816d9e1d039ad372d8775f7a6f4c8cbb4617744eb4320d8c9c8357fb29 |