![]() When subclassing CreateAPIView we get access to all the methods defined in CreateModelMixin and GenericAPIView:ĭef get_serializer (self, *args, **kwargs ) : # leave this intact NOTE: if you want to test this view check out DRF: testing POST requests. So where do we intercept and swap request.data? ![]() But there's no way to swap back request.data with your own object because at this stage request is immutable too. The only way to change it is to copy the object and modify the copy. Request.data in fact is a Django QueryDict which turns out to be immutable. ![]() If only was that easy! If we run this view we get AttributeError: This QueryDict instance is immutable. create (request, *args, **kwargs ) return self. ![]() serializers import ContactSerializerĬlass ContactCreateAPI (CreateAPIView ) :ĭef post (self, request, *args, **kwargs ) : if (name : = request. generics import CreateAPIViewįrom library. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |