Search code examples
djangoimagefield

django imageField returns False when I delete the image


I am using three imageFields in a form. It works well but when I use the (built-in) delete function("effacer") as shown is this image below and I save my form, I get "False" in my database... How can I remove totaly the path ("uploads/...") of the deleted image instead of getting "False" ? Thanks, Here is my model:

class Announce(models.Model):
photo1 = models.ImageField(upload_to='uploads/', blank=True)
photo2 = models.ImageField(upload_to='uploads/', blank=True)
photo3 = models.ImageField(upload_to='uploads/', blank=True)

enter image description here

UPDATE 1:

def modifyannounce(request, idannon*unce):
    if request.method  == 'POST':
            instance = Annonce.objects.get(id=idannounce)
            modif_form = AddAnnounceForm(request.POST, request.FILES, instance=instance)
            if modif_form.is_valid():
                    Annonce.photo1 = modif_form.cleaned_data.get('photo1')
                    Annonce.photo2 = modif_form.cleaned_data.get('photo2')   
                    Annonce.photo3 = modif_form.cleaned_data.get('photo3')
                    modif_form.save()
                    return redirect("/annoncesencours/")

Solution

  • I just removed the cleaned_data method on these fields and I get empty fields in my database