django python: storing foreign key, not from the form POST method, but by
from data I already have
I am a noob guys, I am storing 'payment' model instance via form POST
method but I have the data of the foreign key field already, because I am
coming from a page which list the objects of 'student' model. I am storing
the field of foreign key by input type="hidden" html element.
but when I submit, it shows error
Cannot assign "u'1'": "payment.student" must be a "student" instance.
Request Method: POST Django Version: 1.5.2 Exception Type: ValueError
Exception Value:
Cannot assign "u'1'": "payment.student" must be a "student" instance.
Exception Location: /usr/local/lib/python2.7/dist-> > > >
>packages/django/db/models/fields/related.py in set, line 405 Python
Executable: /usr/bin/python Python Version: 2.7.3
class payment(models.Model):
Id = models.AutoField(primary_key=True)
student = models.ForeignKey('student',db_column='student')
dateTime = models.DateField(auto_now_add=True)
amountDue = models.DecimalField(max_digits=5, decimal_places=2)
I added db_column='student', later, might not have really taken effect in
mysql database.
No comments:
Post a Comment