我在更新员工数据时遇到问题。
我想更新已存在的员工数据。除Resume Field外,所有记录都会更新。当我试图查看数据库时,我发现 FileField:无,但所有其他字段都按预期填充。
我哪里错了?
models.py
class employee_data(models.Model):
eid=models.AutoField(primary_key=True)
f_name=models.CharField(max_length=20)
l_name=models.CharField(max_length=20)
email=models.URLField(unique=True)
username=models.CharField(max_length=30,null=True)
passwd=models.CharField(max_length=30)
location=models.CharField(max_length=30,null=True)
gender=models.CharField(max_length=10,null=True)
mobile=models.CharField(max_length=20,null=True)
jobarea=models.CharField(max_length=30,null=True)
exp=models.CharField(max_length=10,null=True)
current_job=models.CharField(max_length=50,null=True)
skills=models.TextField(null=True)
logincount=models.IntegerField()
resume=models.FileField(upload_to='resume/%Y/%m/%d',null=True)
views.py:
def reg_emp_done(request):
if request.method=='POST':
uid=request.POST['id']
if 'cv' in request.FILES:
form=regform(request.POST,request.FILES)
if form.is_valid:
user=employee_data.objects.get(eid=uid)
user.username=request.POST['uname']
user.location=request.POST['location']
user.gender=request.POST['gender']
user.mobile=request.POST['mob']
user.jobarea=request.POST['jobarea']
user.exp=request.POST['exp']
user.current_job=request.POST['current']
user.skills=request.POST['skills']
user.logincount=user.logincount+1
user.resumefile=request.FILES['cv']
user.save()
return render_to_response('reg_done.html',context_instance=RequestContext(request))
else:
form=regform()
return render_to_response('reg_emp.html',{'msg':'Sorry! Invalid Form','uid':uid},context_instance=RequestContext(request))
else:
form=regform()
return render_to_response('reg_emp.html',{'msg':'Sorry! Resume file is Empty','uid':uid},context_instance=RequestContext(request))
else:
form=regform()
return render_to_response('reg_emp.html',{'msg':'Sorry! Invalid Request, Start over'},context_instance=RequestContext(request))
forms.py:
class regform(forms.Form):
eid=forms.IntegerField()
f_name=forms.CharField(max_length=20)
l_name=forms.CharField(max_length=20)
email=forms.URLField()
username=forms.CharField(max_length=30)
passwd=forms.CharField(max_length=30)
location=forms.CharField(max_length=30)
gender=forms.CharField(max_length=10)
mobile=forms.CharField(max_length=20)
jobarea=forms.CharField(max_length=30)
exp=forms.CharField(max_length=10)
current_job=forms.CharField(max_length=50)
skills=forms.CharField()
logincount=forms.IntegerField()
resume=forms.FileField()
settings.py:
MEDIA_ROOT = '/home/user/Desktop/ojp/media/'
MEDIA_URL = '/media/'
答案 0 :(得分:1)
form method="POST" enctype="multipart/form-data"