1👍
request.POST
is not a normal dictionary, it is actually a QueryDict
object. You need to convert it to a traditional dict, before you can use it as such:
Transaction.objects.create(**request.POST.dict())
I must say, the above is not something I would put in production – there are no checks as to the contents of the dictionary – any malicious/junk can be used to create objects.
You should use forms to validate the input, and then create objects, like this:
class TransactionForm(forms.ModelForm):
class Meta:
model = Transaction
user_input = TransactionForm(request.POST())
if user_input.is_valid():
user_input.save()
Source:stackexchange.com