python - Django form to update an object doesn't keep files -
so i'm working on portfolio site, , i've got form called work represents works in portfolio. work has m2m field normal images, , 1 imagefield main image used thumbnails etc.
my problem following, when go update view created work, old image (that in database) listed in form, no in field itself. says current: [name of image], , regular filefield label edit
.
i don't want user able update work if upload image again. how pass current image form?
#models.py class work(models.model): name = models.charfield(max_length=255) image = models.imagefield( upload_to="images" ) #forms.py class meta: model = work exclude = ('slug',) #views.py def workedit(request, pk): if request.method == "post": form = workform(request.post, request.files) if form.is_valid(): new_work = form.save(commit=true) return redirect("/portfolio/beheer/werk") else: print(form) print(form.errors) else: work = get_object_or_404(work, pk=pk) form = workform(request.post ,request.files, instance=work) context = { 'form': form, } return render(request, 'submit.html', context)
Comments
Post a Comment