【发布时间】:2023-02-04 01:38:06
【问题描述】:
数据被复制而不是在 Django 中被更新,请帮助我克服这个问题我也尝试了更新方法但是我遇到的问题是图像不显示,因此我使用保存方法来保存和复制我不想要的 anthor 对象.它应该更新同一个对象。
视图.py
def EuAdmin(request, pk):
pi = EmailDb.objects.get(id=pk)
if request.method == 'POST':
institution = request.POST.get('institution', '')
fullname = request.POST.get('fullname', '')
email = request.POST.get('email', '')
contact = request.POST.get('contact', '')
position = request.POST.get('position', '')
uploadd = request.FILES.get('upload', '')
sdata = EmailDb(institution=institution, fullname=fullname, contact=contact, email=email, position=position, uploaddata=uploadd)
sdata.save()
return HttpResponseRedirect("/eadmin")
return render(request, 'NEC/eupdate.html', {'pi': pi})
模型.py
class EmailDb(models.Model):
institution = models.CharField(max_length=300, blank=True, null=True)
fullname = models.CharField(max_length=50, blank=True, null=True)
contact = models.IntegerField()
email = models.CharField(max_length=300, blank=True, null=True)
position = models.CharField(max_length=100, blank=True, null=True)
uploaddata = models.FileField(upload_to='appointment_letter')
def __str__(self):
return self.fullname
【问题讨论】:
标签: python-3.x django django-models django-views django-forms