I was confused to why when I run this code it returns an error
create() takes 1 positional argument but 2 were given
if request.method == "POST":
my_form = RawProductCreateForm(request.POST)
if my_form.is_valid():
Product.objects.create(my_form.cleaned_data)
but when I modify on the create method and add ** before passing the cleaned data it works!
Product.objects.create(**my_form.cleaned_data)
It is because
create
takes keyword arguments, likePlacing the
**
before it tells the model to treatmy_form.cleaned_data
as a dictionary of keyword arguments.