Skip to content

Instantly share code, notes, and snippets.

View chriscdn's full-sized avatar

Christopher Meyer chriscdn

View GitHub Profile
@chriscdn
chriscdn / put_as_create.py
Created November 12, 2015 14:37 — forked from tomchristie/put_as_create.py
PUT-as-create mixin class for Django REST framework.
class AllowPUTAsCreateMixin(object):
"""
The following mixin class may be used in order to support PUT-as-create
behavior for incoming requests.
"""
def update(self, request, *args, **kwargs):
partial = kwargs.pop('partial', False)
instance = self.get_object_or_none()
serializer = self.get_serializer(instance, data=request.data, partial=partial)
serializer.is_valid(raise_exception=True)