[Answered ]-Form fields are empty when created using instance = instance

1πŸ‘

βœ…

I am bit confused about how you implemented it. You have passed a instance of WrongPrice price through the form, which is unnecessary, you could have used initial:

wrong_values = dict(
    link=wrong_link,
    correct_price=wrong_price,
    domain = domain
)

form_wrong_price = wrong_price_form(initial= wrong_values)

Then you are adding values to product_prices_form from instance of form_wrong_price. I don’t see why you need a form again here. You can simple use:

form_wrong_price = wrong_price_form(request.POST, initial= wrong_values)
if form_wrong_price.is_valid():
    instance = form_wrong_price.save()
    instance_productprice.start_price = instance.correct_price
    instance_productprice.last_price = instance.correct_price
    instance_productprice.save()

Finally, please use PascalCase when defining class names. And you can get the product prices by product_prices.objects.get(id=pk)(instead of filter()[0]).

πŸ‘€ruddra

Leave a comment