Reputation: 7302
I have overridden the .save() method of one of my models to use an extra argument. My question is: how I can pass this argument through the serializer.save(). My code below:
class DeliveryCreate(generics.CreateAPIView):
queryset = Delivery.objects.none()
serializer_class = DeliverySerializer
permission_classes = (permissions.DjangoModelPermissions, )
def perform_create(self, serializer):
serializer.save(permissions=(self.request.user,) ) #here, how to I do it?
In a normal view I do it like this: self.object.save(owner=self.request.user)
I have tried: serializer.save(permissions=(self.request.user,),owner=self.request.user )
and it does not work
Thanks for any help
Upvotes: 4
Views: 2207
Reputation: 734
According to the docs serializer.save(owner=self.request.user)
should be enough. The keyword arguments will be included in the validated_data argument when .create()
or .update()
are called on the serializer. It would help if you posted the traceback you're getting and your model/serializer code as Rahul Gupta suggested.
Upvotes: 2