The create function under the hood looks more less like this:
def create(self, **data):
pass
As you can see you have one positional argument self
, other one is just a key words dictionary. When you call this function like this:
Product.objects.create(my_form.cleaned_data)
You are passing two positional arguments one is objects
this is how python handle classes and methods and other one is my_form.cleaned_data
, but the function exptes only one positional and any numbers of named arguments.
In second call:
Product.objects.create(**my_form.cleaned_data)
lets say the my_form.cleaned_data
looks like this:
{
'age': 1,
'name': 'good product'
}
so the equvialent of the second call would be
Product.objects.create(name='good product', age=1)
As you can see you have only one positional argument objects
and 2 named arguments.
In create function you can refer to data like this:
def create(self, **data):
name = data['name']
age = data['age']