型號:無法分配 「U'' 」: 「Vote.design」 必須是一個 「設計」 實例
class Vote(models.Model):
user = models.ForeignKey(User)
design = models.ForeignKey(Design)
vote = models.DecimalField(max_digits=2,decimal_places=1, choices=RATE_CHOICES)
觀點:
def add_vote(request, id, vote):
user = request.user
Vote.objects.create(user=user, design = id, vote = vote)
return HttpResponseRedirect('/')
網址:
url(r'^vote/(?P<id>\d+)/(?P<vote>\d{1,5})/', 'app.views.add_vote'),
如果我嘗試例如:
127 .0.0.1:8000 /票/ 1/3
我有這樣的錯誤:
ValueError at /vote/1/3/
Cannot assign "u'1'": "Vote.design" must be a "Design" instance.
1爲['get_object_or_404'](HTTPS://docs.djangoproject。 COM/EN /開發/主題/ HTTP /快捷鍵/#GET-對象或-404) – 2013-03-11 11:44:42