0
Thanks everyone for the feedback and the time+effort.
At last after a lot of try-error I found the solution
It seems that even if you have an autogenerated id that is not part of your model you have to pass it by parameter anyway, and as like normal SQL it can be done by passing a NULL value or the Python equivalent None
So, the answer is
Rose = Producto.objects.get(id=124105)
cot = Cotizacion(None, 13, 141, 15, Rose)
cot.save()
1
This is happening because the ForeignKey
field does not allow null values by default, but you’re trying to initialize an instance of the Cotizacion class without a reference to any Producto instance.
- How to setup a virtual environment for Python 3.6
- How do I 'cleanly' create this Django/DRF serialization relationship between models?
- Clean() method causes files to lose data using POST form
0
You’re trying to initialize Cotization with three arguments where definition of this model expects five of them.
Are we talking still about Cotization or maybe Producto?
Update (after original post was updated about additional data):
Please take a look on this link. Please use underscore character or just full object. “dot” notation is same optimal as giving full object.
cot = Cotizacion(minimo, maximo, promedio, cantidad, producto_id)
or
cot = Cotizacion(minimo, maximo, promedio, cantidad, producto)
- Get specific user information in Django template
- TypeError: 'function' object has no attribute '__getitem__' from urls.py
- Passing multiple variables from the template to a view
- How do we tell where a django redirect comes from
- How I can use class-based view in ViewSet?