本文介绍了Foriegnkey问题提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这篇文章在以django形式提交数据时扩展了

Here i want to insert the data directly into table ,if person click on http://127.0.0.1:8000/

但它会抛出以下错误任何想法?

But it throws below error any thoughts ??

异常类型:ValueError at /
异常值:无法分配u'x:working.w_name必须是配置文件实例。

Exception Type: ValueError at /Exception Value: Cannot assign "u'x'": "working.w_name" must be a "Profile" instance.

推荐答案

我以为你在说你想把值注入表单?

I thought you were saying you wanted to inject values into a form?

在这种情况下,这很清楚(看到它比评论更好),您需要将配置文件实例传递给您的工作对象,就像我们在表单中

In this case, it's clear (see it's better than comments), you need to pass in a Profile instance to your working object just as we did in the form clean method in your other post.

def index(request):
   try:
       profile = Profile.objects.get(pk='X')
   except Profile.DoesNotExist:
       assert False # or whatever you wish
   obj=working()
   obj.w_name= profile
   obj.Monday=1
   obj.Tuesday=2
   obj.Wednesday =3
   obj.save()
   return http.HttpResponse('Added')

这篇关于Foriegnkey问题提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:29