I have a simple PATCH
method, where I sent a bunch of paramaters to my object Foo
, including a parameter new_bar
. I want to first patch all the other fields, and then append new_bar
to the current obejcts bar
data.
I'm having issues where Django refuses to accept my override of partial route (error:
response = handler(request, *args, **kwargs) TypeError: decorator() takes exactly 1 argument (3 given))
How can I override my PATCH method to accept this paramater bar
on my object food, and append it. I am sending in the new data as key new_bar
to not confuse Django and get caught in the initial patch step:
@detail_route
def partial_update(self, request, *args, **kwargs):
serializer = FooSerializer(data=request.data, partial=True)
serializer.is_valid()
instance = serializer.save()
bar = self.request.POST.get('new_bar', None)
if bar:
if len(instance.bar) == 0:
instance.bar = bar
else:
# Append
bar = json.loads(bar)
old_bar = json.loads(instance.bar)
instance.bar = json.dumps(oldbar)