我正在尝试更新模型数据库中的特定字段值。
我想我已经尝试了一切。...我很沮丧...
型号:
class Student(models.Model):
GRADELEVEL=[('P', 'Pre-K'), ('K', 'Kindergarten'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'),('6', '6'),('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11'), ('12', '12')]
epicenterid = models.CharField(null=False, blank=False, max_length=6)
studentlname = models.CharField(max_length=50)
studentfname = models.CharField(max_length=50)
parentemail = models.CharField(max_length=120)
parentphone = models.CharField(max_length=50)
studentemail = models.CharField(max_length=120)
studentphone = models.CharField(max_length=20)
studentgrade = models.CharField(max_length=120, choices=GRADELEVEL)
readingperformancelevel = models.CharField(max_length=20, choices=GRADELEVEL)
mathperformancelevel = models.CharField(max_length=10, choices=GRADELEVEL)
studentbirthday = models.CharField(max_length=10)
regularteacheremail = models.CharField(max_length=10)
regularteacherlname =models.CharField(max_length=10)
regularteacherfname =models.CharField(max_length=10)
studentcreatedate = models.DateTimeField(auto_now=True)
查看:
def edit_student_view(request):
form = EditStudentForm(request.GET or None)
q=Student.objects.all()
epicenterid=q.epicenterid()
if form.is_valid():
epicenteridtoupdate = (EditStudentForm.GET.get())
q=Student.objects.all()
epicenterid=q.epicenterid()
search = Student.filter(epicenterid=epicenteridtoupdate)
search.update(studentfname='New First Name')
context = {'form': form}
return render(request, 'enrollment/editthisstudent.html', context)
我可以通过将id号放入update命令中来更新特定的记录,但是它绝对不会从用户输入中搜索并找到传递的epicenteridtoupdate
变量。
请帮助。...