models.py:
Picture = models.ImageField('Picture', null=True, blank=True)
When I give the command
person.Picture.delete()
the picture is deleted from the directory, but in the database still has the record of the file path in Picture as shown in image below. How can I delete it?
CodePudding user response:
Set the field to None
as well, so:
person.Picture.delete()
person.Picture = None
person.save()
Note: normally the name of the fields in a Django model are written in snake_case, not PascalCase, so it should be:
picture
instead of.Picture
CodePudding user response:
You need to try
person = Person.objects.get(User=User_)
person.Picture.delete(save=False)
...
person.save()
Try setting the path in your model something like below
Picture = models.ImageField(upload_to='Picture', null=True, blank=True)
CodePudding user response:
Try this person.Picture.delete(save=False)