Is there a way send JS data to Views?

Posted by: fennec.byword0t on 11 September 2022, 7:07 pm EST

  • Posted 11 September 2022, 7:07 pm EST

    I’m trying to send JS data to Views ( index of a an item). When a customer clicks on one of the stars to rate the product, JS gets the index of the star +1, and some how I would like to add this const listIndex = newChildren.indexOf(item) + 1 to the product review form. On Views, set review.rating = listIndex. Is there a way to do it? Any help will be greatly appreciated. Thank you. Here is the code snippets:

    {% csrf_token %} {{ form|crispy }}

    Rating:

    Submit Cancel

    @login_required

    def product_review(request, pk):

    user = request.user

    customer = Customer.objects.filter(name=user).first()

    product = Product.objects.filter(pk=pk).first()

    if request.method == “POST”:

    form = ProductReviewForm(request.POST)

    if form.is_valid():

    review_form = form.save()

    review = ProductReview.objects.get(pk=review_form.pk)

    review.author= customer

    # review.rating = “”

    review.product.add(product)

    review.save()

    return redirect(“store:my_orders”)

    else:

    form = ProductReviewForm()

    context = {

    “form”: form,

    “product”: product

    }

    return render(request, “store/product_review.html”, context)

    class ProductReview(models.Model):

    product = models.ManyToManyField(Product, related_name=“product_review”)

    author = models.ForeignKey(Customer, on_delete=models.SET_NULL, null=True)

    review_title = models.CharField(max_length=100)

    content = models.TextField()

    date = models.DateTimeField(default=timezone.now)

    rating = models.IntegerField(default=0)

    def __str__(self):
        return f"{self.author}: {self.review_title}"
    
  • Posted 12 September 2022, 7:57 pm EST

    Hi,

    Could you please share a working sample and explain the use case and how exactly you are using DataViewJs so that we could have a better understanding of the issue and help you accordingly?

    Regards,

    Avinash

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels