I have a django rest framework view set. I want to create an object based on data that is passed in with the post request. I have it setup right now to create new object with dummy data before it starts to take information from the request. I am getting the following error:
create() takes 1 positional argument but two were given.
Here is my viewset method:
@permission_classes((IsAuthenticated)) def create_user(self, request): data = { 'version':1, 'path':'testingpath1', 'namespace':'testingnamespace1', 'value':'testin value', 'user_id':1, 'person':request.user } return Preference.objects.create(data)
Advertisement
Answer
Pass keyword arguments to create
method like **data
instead of data
.
Change return Preference.objects.create(data)
to return Preference.objects.create(**data)