1👍
You are making a super()
call with the wrong parameters, it should be:
def create(self, request, *args, **kwargs):
product_id = self.kwargs['pk']
if Like.objects.filter(user=self.request.user, product_id=product_id).exists():
raise ValidationError(_("This user already likes this product"))
else:
return super().create(request, *args, **kwargs)
0👍
The issue is how you’re calling create()
Try the below:
In the PythonKuba/api/ecommerce/views.py
file
return super().create(request=self.request, product_id=product_id, **kwargs)
At the moment you are sending in the user, not the request
- [Answered ]-Django – how to perform search with multiple fields and ModelForm
- [Answered ]-Django Template changing html attribute based on slug and current request
- [Answered ]-Is it possible to add more fields to admin/auth/user?
- [Answered ]-How to add "$" in a Integer Field in Django in admin interface?
- [Answered ]-Getting "database error" (using django, djangotoolbox, mongodbengine of Django-nonrel)
Source:stackexchange.com