我想编辑一些内容,但是某些字段未填充当前选定的值。例如:DateField和ModelChoiceField
这是我当前的代码
views.py
def pacient_update(request, pk):
instance = get_object_or_404(Pacient.objects.filter(medic=request.user.medic), pk=pk)
instance_a = get_object_or_404(AdresaUseri, pk=pk)
pacient = PacientForm(request.POST or None, instance=instance)
adresa = AdresaForm(request.POST or None, instance=instance_a)
if pacient.is_valid() and adresa.is_valid():
instance = pacient.save(commit=False)
instance.save()
instance_a = adresa.save(commit=False)
instance_a.save()
context = {
'instance':instance,
'form': pacient,
'form_a': adresa,
}
return render(request, 'pacienti/adaugare.html', context)