楷模:
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
我有这个错误:
/vote/1/3/ 处的 ValueError
无法分配“u'1'”:“Vote.design”必须是“Design”实例。