0

I have a view which does the following:

  1. Scrape som prices from a product-page.
  2. Return a HTML page with a picture of each product incl. the price (like a check-out cart from a webshop)

If the price is incorrect, the user should then be able to modify the price for each product, and atlast click one button, which then saves the products.

Right now I have my view

#views.py
def my_products(request):
    user = request.user
    
    if request.method == "POST":
        form = MyForm(request.POST)    
        if form.is_valid():
            domain = form.cleaned_data["domain"]
            discount_pct = form.cleaned_data["discount_pct"]
            link = form.cleaned_data["link"]
            
            #Extract info for each link
            prices,links,images,errors  = scrape_pagee(domain,link)         

            context = {
                "data":zip(prices,links,images)} 
            return render(request, "myapp/list_confirm.html",context=context)
    else:
        add_form = MyForm()
    context = {
        "add_form":add_form,
        
    }
    return render(request, "myapp/add_list.html",context=context)

where prices, links are array of the given prices and the link to each product

e.g prices = [600,200,159], links = ["www.webshop1.com/shirt","www.webshop2.com/jeans","www.webshop1.com/socks"]

I think parsing the forms isn't a problem (I assume it is just parsing an array of Forms to the context and loop over them in the HTML page), but it's more how to submit them all in one "save" button, and how to distinguish them from eachother in the POST-request.

CutePoison
  • 3,725
  • 4
  • 21
  • 32
  • Does this answer your question? [Making a Django form class with a dynamic number of fields](https://stackoverflow.com/questions/5478432/making-a-django-form-class-with-a-dynamic-number-of-fields) – Ezra Jun 29 '21 at 17:22

0 Answers0