我有一个 HTML 页面,它显示从我的数据库中获取的详细信息,该数据库已经存储。我必须编辑我的详细信息,并且详细信息必须替换我的旧内容 id db(即;过度写入同一字段)。我正在使用 MySQL 数据库。我已经添加了我的代码。当我提交表单时,它没有更新到数据库中。检查一下,这段代码是否正确?
模型.py
class js_details(models.Model):
user = models.ForeignKey(User, unique=True)
#PERSONAL INFO
fname = models.CharField(max_length=30)
contactno = models.IntegerField(max_length=30)
emailid = models.EmailField(max_length=30)
dob = models.IntegerField(max_length=30)
表格.py
class EditForm(forms.ModelForm):
class Meta:
model = js_details
exclude = ('user')
视图.py
def editresume(request):
user = request.user
profile_info = js_details.objects.filter(user_id=user)
profile_data = { "profile_detail" : profile_info }
if request.method == "POST":
edit = EditForm(request.POST, request.FILES, instance = request.user.get_profile())
if edit.is_valid():
edit.save()
return HttpResponseRedirect('/accounts/Profile/')
else:
edit = EditForm(instance = request.user.get_profile())
return render_to_response('registration/personal_information.html', profile_data, context_instance=RequestContext(request))
个人信息.html
<h4> Personal Details</h4>
<table width="90%" border="0">
<tr>
<td width="30%">
<p> Name </p>
<p> Contact Number </p>
<p> Email ID</p>
<p>DateOfBirth</p>
</td>
<td width="30%">
<p>{% for detail in profile_detail %}{{ detail.fname}} {{ detail.lastname}}{% endfor %}</p>
<p>{% for detail in profile_detail %}{{ detail.pri_contact }}{% endfor %}</p>
<p>{{ user.email }}</p>
<p>{% for detail in profile_detail %}{{ detail.dob }}{% endfor %}</p>
</td>
<td width="30%">
<p><a href="">Edit</a></p>
</td>
</tr>
</table>