1đź‘Ť
Found the problem, guess it’s my fault for not including forms.py in the question
THE WRONG ONE
class TempCart(forms.ModelForm):
Product_ID = forms.CharField(max_length=80, label="Product ID")
HowMany = forms.IntegerField(label='HowMany')
DateSubmit = forms.DateTimeInput()
class Meta:
model = Cart
fields = ["Product_ID","HowMany","DateSubmit",]
Problem was with the fields
all it takes to fix the problem is deleting the “Product_ID”
fields = ["HowMany","DateSubmit",]
Thank you all for helping me
Cheers
but if it is not too much to ask can anyone explain why this is happening?
why do django decilne the “Product_ID” on the fields?
0đź‘Ť
For begining fix this little syntax mistake:
VarProductId = Product.objecrs.get(PId=”Product_ID”) *Product.objects.get
- Django, Django REST Framework, Internet Explorer and CSRF token missing or incorrect
- 'TypeError: 'DotMap' object is not callable' error at django model class
0đź‘Ť
“Cannot assign “15”: “Cart.Product_ID” must be a “Product” instance.”
Above signifies that you are trying to insert a row in Cart table with Product_Id = 15. Since this is a foreign key, Product_Id should be present in class / table Product. First please insert the value in Product before inserting the row in class Cart. This should work.
- Python if elif else only returning first output without using logic
- Django get custom m2m field value
0đź‘Ť
There are a few this apart from the solution I want to mention:
- What I feel is somehow the web server you have started has not been
refreshed. try restarting it if possible. Seems to me that is the
issue here. -
If there is a spelling mistake in
objecrs
you will an exception stating is not a valid manager rather than 15. -
Try to log/print the type of
VarProductId
before assigning it. -
Don’t prefix
Var
for all variables. It is not the way to write clean code. Also everything in python is an object. So there is no
sense in prefixing itvar
. -
After checking form.is_valid() always use
form.cleaned_data
to fetch the data you want. Not from request.
0đź‘Ť
Other than your objecrs
typo, this code should run fine.
Try deleting your .pyc
files (specifically views.pyc
) and restarting your development server.