mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 17:09:59 +03:00
feat #6084: Adding mixin that allows for many object creations.
The original issue #6084 has an issue where the browsable api cannot create multiple objects, but sometimes being able to creat more than object object is desired. This commit proposes a mixin that allows for one or more objects to be created, which allows normal browsable api operation, and the use case of creating more than one instance.
This commit is contained in:
parent
7bd730124c
commit
d845ba32b3
|
@ -30,6 +30,19 @@ class CreateModelMixin:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
class CreateOneOrMoreModelMixin(CreateModelMixin):
|
||||||
|
"""
|
||||||
|
Create one or more model instances.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get_serializer(self, *args, **kwargs):
|
||||||
|
if self.request.method == 'POST':
|
||||||
|
kwargs['many'] = isinstance(self.request.data, list) or kwargs.get(
|
||||||
|
'many', False
|
||||||
|
)
|
||||||
|
return super().get_serializer(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class ListModelMixin:
|
class ListModelMixin:
|
||||||
"""
|
"""
|
||||||
List a queryset.
|
List a queryset.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user