Re: Django - File or Image Delete

82 views
Skip to first unread message
Message has been deleted

Mstislav Kazakov

unread,
Jul 8, 2016, 11:41:57 AM7/8/16
to Django users
Just pass empty value in file field.
If blank=True and null=True, everything should work fine and image will be removed.

пятница, 8 июля 2016 г., 17:23:42 UTC+5 пользователь sevenr...@gmail.com написал:

The user has the possibility to add/delete image and documents.


I used GCBV UpdateView and a FormModel for this.


How can I offer the possibility to the user to delete the file/image ?

Message has been deleted

Mstislav Kazakov

unread,
Jul 11, 2016, 4:16:27 AM7/11/16
to django...@googlegroups.com
Try to override `delete` method in your model. You should do something like this:
class Example(models.Model):
    f = models.FileField(null=True, blank =True)   


    def delete(self,*args,**kwargs):
        if os.path.isfile(self.f.path):
            os.remove(self.f.path)

        super(Example, self).delete(*args,**kwargs)

2016-07-09 21:04 GMT+05:00 <sevenr...@gmail.com>:
This way the Image is removed from database, not from the server.

--
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 post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bdd2edd2-d232-416e-9ff4-b5b3519e6c1e%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages