django-rest-framework-bulk | Django REST Framework bulk CRUD view mixins | REST library
kandi X-RAY | django-rest-framework-bulk Summary
kandi X-RAY | django-rest-framework-bulk Summary
Django REST Framework bulk CRUD view mixins
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Create a new object
- Performs bulk create
- Bulk delete objects
- Allow bulk destroy operation
- Perform bulk destroy operation
- Performs the destroy operation
- A partial update
- Bulk update the object
- Performs bulk update
- Update the model
- Read the contents of a file
django-rest-framework-bulk Key Features
django-rest-framework-bulk Examples and Code Snippets
from rest_framework_bulk import BulkSerializerMixin, BulkListSerializer
from rest_framework_bulk.drf3.serializers import BulkSerializerMixin, BulkListSerializer
Community Discussions
Trending Discussions on django-rest-framework-bulk
QUESTION
I have many endpoints which use ModelViewSet
to manage CRUD operations for my models.
What I am trying to do, is to add bulk create, update, and delete at these same endpoints. In other words, I want to add POST
, PUT
, PATCH
and DELETE
to the collection endpoint (e.g.: /api/v1/my-model
). There is a django-rest-framework-bulk
package available, but it seems to be abandoned (hasn't been updated in 4 years) and I'm not comfortable using a package in production that is no longer active.
Additionally, There are several similar questions here that have solutions, as well as blog posts I've found. However, they all seem to use the base ViewSet
, or APIView
, which would require re-writing all of my existing ModelViewSet
code.
Finally, there is the option of using the @action
decorator, however this would require me to have a separate list endpoint (e.g.- /api/v1/my-model/bulk
) which I'd like to avoid.
Are there any other ways to accomplish this while keeping my existing ModelViewSet
views? I've been looking at GenericViewSet
and mixins, and am wondering if creating my own mixin might be the way to go. However, looking at the mixin code, it doesn't appear that you can specify an HTTP Request method to be attached to a given mixin.
Finally, I have tried creating a separate ViewSet
that accepts PUT and adding it to my URLs, but this doesn't work (I get a 405 Method not allowed when I try to PUT to /api/v1/my-model
). The code I tried looks like this:
ANSWER
Answered 2019-Aug-28 at 17:18I know you said you wanted to avoid adding an extra action but in my opinion it's the simplest way to update your existing views for bulk create/update/delete.
You can create a mixin that you add to your views that will handle everything, you'd just be changing one line in your existing views and serializers.
Assuming your ListSerializer
look similar to the DRF documentation the mixins would be as follows.
core/serializers.py
QUESTION
I am using Django Rest Framework and I have a situation similar to the Album and Tracks example used in the documentation here: http://www.django-rest-framework.org/api-guide/relations/#api-reference
I want to make an endpoint that allows me to post this JSON data
...ANSWER
Answered 2017-Nov-24 at 05:45Firstly, I would recommend removing that unique constraint, it will make your life way more difficult in my opinion.
Seriously, I don't think putting a unique constraint on the ordering is a good idea, remove it, ensure validation for sane values, and cascade your ordering, moving on...
If you want to update the ordering of your tracks you'll need to juggle around the orders, heres some python pseudocode:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install django-rest-framework-bulk
You can use django-rest-framework-bulk like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page