I store information in the following database, particularly an image.
class client(models.Model):
id = models.AutoField(primary_key=True)
password = models.CharField(max_length=200)
email = models.EmailField()
random_number= models.IntegerField(default=0)
name = models.CharField(max_length=200, blank=True)
last_name = models.CharField(max_length=200, blank=True)
picture=models.ImageField(upload_to='media/', blank=True)
qualification=models.IntegerField(default=0)
The image when it is save goes to media folder. The next function in views.py delete the data which it is storage:
@csrf_exempt
def newPersonalInfo(request):
if request.method == 'POST':
if request.POST.get("type")=="1":
objet=client.objects.filter(email=request.POST.get("email"))
if not objet:
return HttpResponse("bad data")
else:
email=objet.first().email
password=objet.first().password
objet.first().delete()
#Here all the information, including the image stored in the media, must be deleted in order to save new data.
new=client()
new.email=email
new.password=password
new.name=request.POST.get("name")
new.last_name=request.POST.get("last_name")
new.picture= request.FILES.get("image")
new.qualification=request.POST.get("qualification")
new.save()
return HttpResponse("ok")
With the sentences objet.first().delete(), Is the image delete from media folder, too? Or I must do something else too?