delete image url from database

25 views
Skip to first unread message

Nuno Vieira

unread,
Oct 16, 2019, 10:23:07 AM10/16/19
to Django users
Hi there,

i am creating a real estate app and i want users to insert and delete images for the houses.

It's all working great except the delete. 

In my views.py i have the code: 

listing = Listing.objects.get(id=1511)
            if listing:
                listing.photo_5 = None
                listing.save(['photo_5'])
                return True

photo_5 is an Imagefield and i want to change the value of that field in database to None.

Why is not changing?

Thanks for your help.

Anirudh Jain

unread,
Oct 16, 2019, 10:47:01 AM10/16/19
to django...@googlegroups.com
First of all, are you saving image url explicitly in database ? You dont need to so that to show/delete any image.

Second, try delete() for deletint image entry.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f24fda94-428d-4f76-b632-4078d948fdcf%40googlegroups.com.

Nuno Vieira

unread,
Oct 16, 2019, 10:57:50 AM10/16/19
to Django users
I am saving the image to media folder and save the url in database.

photo_5 = models.ImageField(upload_to='photos/%Y/%m/%d/'blank=True)

Then when the user clicks in trash can icon, i have an ajax request to delete the image from database. But there is the problem, i am not able to update the url in database or to delete. I already tried with update Listing.objects.all().filter(id = 1511).update(photo_5 = None)

It seems that i can not change the value of photo_5.
Reply all
Reply to author
Forward
0 new messages