Dear All,
*Note: trying to make Django rest Api for eCommerce project.*
I am working drf eCommerce project.
I am trying to make product rating and review Django Rest Api.
*Models.py*
class Product_review(models.Model):
user_id = models.ForeignKey(User_registrations,
on_delete=models.CASCADE)
product_id = models.ForeignKey(Techshop, on_delete=models.CASCADE)
product_rating = models.IntegerField()
product_created_rating_date = models.DateTimeField(auto_now_add=True,
null=True)
product_review = models.ForeignKey(on_delete=models.SET_DEFAULT,
null=True, default = "NA")
product_created_review_date = models.DateTimeField(auto_now_add=True,
null=True)
Serializer.py
class Product_review(serializers.Serializer):
product_code = models.IntegerField(null=True)
product_rating = models.IntegerField()
product_review = models.TextField(max_length=3000)
product_created_rating_date = models.DateTimeField(auto_now_add=True,
null=True)
def validate(self, data,email):
product_code = data.get("product_code")
product_rating = data.get("product_rating")
product_review = data.get("product_review")
user_data = User_registrations.objects.get(email=email)
product_code = Techshop.objects.get(product_code, product_rating,
user_data)
if int(product_rating) <= 5 and int(product_rating) => 1:
if product_rating == 1:
print("Poor")
elif product_rating == 2:
print("Average")
elif product_rating == 3:
print("Good")
elif product_rating == 4:
print("Very Good")
elif product_rating == 5:
print("Excellent")
else:
continue
else:
continue
*views.py *
class Product_reviewView(APIView):
def post(self,request):
try:
rt = TokenAuthentication()
g = rt.authenticate(request)
if g[1]:
serializer = Product_review.validate(None,request.data,
g[0])
return Response(serializer,status=HTTP_200_OK)
else:
raise serializers.ValidationError(g)
except Exception as e:
raise serializers.ValidationError(e)
I need to find ratings for particular user and my side I am taking uniqe as
product code.
Thanks
django user
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CA%2BAqMUczWR6nSsk2ZBJtjKft9m0bRJFFEhf0_TSuj7zNdG_MHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.