Regarding to trying to make Django rest Api for eCommerce project.

8 views
Skip to first unread message

RONAK JAIN

unread,
Jun 6, 2019, 3:38:56 AM6/6/19
to django...@googlegroups.com
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

Reply all
Reply to author
Forward
0 new messages