DRF Deleterious: A simple mixin package for Django REST Framework which adds Deleting Multiple requested entities in a single DELETE request
Project description
DRF Deleterious
DRF Deleterious is a simple mixin package for Django REST Framework which adds the ability to delete multiple requested entities in a single DELETE request.
Features
- Delete multiple model objects based on matching IDs provided in the request body.
- Customizable success and error messages.
- Default endpoint is at "/", the same as the list method of a viewset, but can be overridden.
Installation
Install the package using pip:
pip install drf-deleterious
Requirements
- Python >= 3.8
- Django >= 4.0.2
- djangorestframework >= 3.14.0
Usage
After installing the package, you can use the DeleteMultipleMixin
in your Django REST Framework views.
Basic Usage
from deleterious import DeleteMultipleMixin
from rest_framework import viewsets
from myapp.models import MyModel
from myapp.serializers import MyModelSerializer
class MyModelViewSet(DeleteMultipleMixin, viewsets.ModelViewSet):
queryset = MyModel.objects.all()
serializer_class = MyModelSerializer
Customizing Messages and URL Path
You can customize the messages and URL path by overriding the class attributes.
class CustomDeleteMultipleViewSet(DeleteMultipleMixin, viewsets.ModelViewSet):
queryset = MyModel.objects.all()
serializer_class = MyModelSerializer
# Custom messages
invalid_body_message = "Please provide valid {model_name} IDs."
none_exist_message = "None of the {model_name} IDs exist."
success_message = "{count} {model_name}(s) were successfully deleted."
error_message = "Error occurred: {error}"
# Custom URL path
delete_multiple_url_path = "delete-multiple"
Example
Here is a more complete example of how to use DeleteMultipleMixin
in a Django REST Framework viewset.
from rest_framework import viewsets
from deleterious import DeleteMultipleMixin
from myapp.models import MyModel
from myapp.serializers import MyModelSerializer
class MyModelViewSet(DeleteMultipleMixin, viewsets.ModelViewSet):
queryset = MyModel.objects.all()
serializer_class = MyModelSerializer
In this example, MyModelViewSet
will handle DELETE requests to delete multiple MyModel
instances.
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
License
This project is licensed under the MIT License.
## Acknowledgements
Inspired by the needs of Django REST Framework users who require batch deletion functionality.
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
File details
Details for the file drf-deleterious-0.1.0.tar.gz
.
File metadata
- Download URL: drf-deleterious-0.1.0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6597ec106ab50029807f9ad1fbba6271b3ea9f91297f8059ed68ec51247f4de |
|
MD5 | 1ac25a8ed5b94a93e3f1e23939302e0c |
|
BLAKE2b-256 | 6bd16592d95013ec559e792b618c484c00156316d610c8412b8be014819dffe7 |