Open baaaam771 opened 3 years ago
closets/templates/record.html 에서 객체 수정 (CRUD중에 U)
form의 instance 이용해 기존 값 호출
근데 수정 하고 입력 누르면 안됨 그리고 수정할 때 기존에 등록했던 이미지 불러오고 싶은데 안된다
closets/views.py
def update(request, pk): cloth = get_object_or_404(Newcloth, pk=pk) form = NewclothPost(instance=cloth) if request.method == "POST": if form.is_valid(): cloth.cloth_name= request.cleaned_data['cloth_name'] cloth.shoulder= request.cleaned_data['shoulder'] cloth.chest= request.cleaned_data['chest'] cloth.arm= request.cleaned_data['arm'] cloth.total_length= request.cleaned_data['total_length'] cloth.image= request.cleaned_data['image'] form.save() return render(request, 'record.html') else: return render(request, 'home.html') return render(request, 'update.html', {'form':form})
cleaned_data method는 이걸 사용하시려고 한건가요? https://docs.djangoproject.com/en/3.1/ref/forms/api/#django.forms.Form.cleaned_data
closets/templates/record.html 에서 객체 수정 (CRUD중에 U)
form의 instance 이용해 기존 값 호출
근데 수정 하고 입력 누르면 안됨 그리고 수정할 때 기존에 등록했던 이미지 불러오고 싶은데 안된다
closets/views.py