1

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/")
al78310
  • 83
  • 9
  • You shouldn't be getting False in your database. I set up an example project with your Announce model and when I check Effacer (clear?), the database shows an empty cell, not False. Does you have custom code like overriding save method or custom image model ? – Jarad Mar 24 '21 at 17:28
  • @ Jarad Yes "effacer" means "clear" in french. I updated my answser to show my view – al78310 Mar 25 '21 at 02:27
  • @Jarad I found the solution, thanks for your time. – al78310 Mar 25 '21 at 03:11

1 Answers1

1

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

al78310
  • 83
  • 9