我有两个表如下
class form1(models.Model):
name=models.CharField(max_length=20)
keyskills=models.CharField(max_length=50)
def __unicode__(self):
return self.name
class form2(models.Model):
keyskills=models.CharField(max_length=20)
na=models.ForeignKey(form1)
def __unicode__(self):
return self.keyskills
def clean(self):
keyskills=self.keyskillls
我的意见.py
if request.method=='POST':
n=request.POST.get('name1')
k=request.POST.get('key1')
form2(na_id=n,keyskills=k).save()
return HttpResponseRedirect('/add')
else:
return render(request,"search.html")
搜索.html
<form action="." method="post">{% csrf_token %}
name:<input type="text" name="name1"><br>
keyskill:<input type="text" name="key1"><br>
<input type="submit" id="click1" value="save">
</form>
如何使用外键为名称字段赋值?,我试过但我没有得到