Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7086559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:33:53+00:00 2026-05-28T07:33:53+00:00

I have a two models, each with an image. One has a foreign key

  • 0

I have a two models, each with an image. One has a foreign key to the parent. When I delete the parent I want to delete the parent and child along with their image file on the disk. To do that I override the delete method:

class MyModelParent(models.Model):
   image = models.ImageField(upload_to = "images/" )

   def delete(self, *args, **kwargs):     
      if self.image:
          self.image.delete()
      super(MyModelParent, self).delete(*args, **kwargs)

class MyModelChild(models.Model):
   parent = models.ForeignKey(MyModelParent)
   image = models.ImageField(upload_to = "images/" )

   def delete(self, *args, **kwargs):     
      if self.image:
          self.image.delete()
      super(MyModelChild, self).delete(*args, **kwargs)

When I delete an instance of MyModelParent, its overridden delete() gets called, but not the ones of the children (even though they get deleted from the DB), so their images remain on the disk. Anyone know what I am doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:33:53+00:00Added an answer on May 28, 2026 at 7:33 am

    You’re not doing anything wrong. The problem is that the delete() method of any child is not called when cascading.

    From the documentation for delete (cascaded delete uses the database query):

    The delete() method does a bulk delete and does not call any delete()
    methods on your models. It does, however, emit the pre_delete and
    post_delete signals for all deleted objects (including cascaded
    deletions).

    However, the pre_delete and post_delete signals are still sent. What you need to do is connect a callback that will listen for one of these signals and do any extra cleanup needed.
    See the relevant documentation for more information on connecting signals.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models: Show and Venue . Show has one venue while each
I have two models, Image and Tag . Each Image object can have more
I have two models, User and Account. Each user may have one account. Creating
I have two models, Order and UserProfile. Each Order has a ForeignKey to UserProfile,
Let's say you have two models: Post and Category . Each Post has a
so i have got two models with each one controller: Model Project has_many Themes
If I have two types of models that each reference each other, whichever one
I have defined two models where each one references the other, like so: class
I have two models (ModelA and ModelB), and FactoryGirl factories for each. I want
I have two models, Forums and Topics, Forums has many Topics. Each has an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.