I have a model for users to add time to a task.
class Time(models.Model):
to_task = models.ForeignKey(Task)
appuser = models.ForeignKey(CustomUser)
hours = models.DecimalField(max_digits=5, decimal_places=2)
However when I try to create an instance of this model by using the following:
t1=Time(totask=task, appuser=user, hours=6.75)
I get an error:
TypeError: 'totask' is an invalid keyword argument for this function.
I have not made any models with multiple ForeignKeys before so am thinking that it could be because of that. However I have seen examples in the Django documentation with two ForeignKey’s and they did the exact same as I did.
After many searches I still can’t figure it out.
The problem is that you have define it as
to_taskin your model so you need to use the same name when creating an instance:Don’t forget to save it:
You can use the
createmethod too: