How to delete File Field and File(in project root) in django?

I want to delete the data inside the file field and the file uploaded through the file field.

I'm beginner.

class Fruits(Signable):
    name = models.CharField(
    description = models.TextField(
        null=True, blank=True,
    this_is_my_file = models.FileField(
        _('Photo image'),

    def __str__(self):
    def delete(self, *args, **kwargs):
        if self.this_is_my_file:
        super().delete(*args, **kwargs)

Like the code above, I added 'def delete' to the existing model as shown above through search.

But I don't know how to use this function.

How do I use this in view and template?

My part of view is below.


class FruitsDetailView(LoginRequiredMixin, DetailView):
    template_name = 'frutis/detail.html'
    login_url = 'login'
    model = MyObjects

    def get_context_data(self, **kwargs):
        pk =
        context = super().get_context_data(**kwargs)
        return context

How do I execute the delete function in this view?

I want to delete it when I press the 'delete' button on the template.

Should I send a post request from template and receive it from view?

I've been thinking about it for 4 days, but I don't know what to do.

Back to Top