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 8952061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:47:26+00:00 2026-06-15T13:47:26+00:00

I have three model classes in a Django app: class Folder(models.Model): … folder =

  • 0

I have three model classes in a Django app:

class Folder(models.Model):
  ...
  folder = models.ForeignKey('Folder',null=True,blank=True,related_name='folders')
  front_thumbnail_image = models.ForeignKey('Image',verbose_name='Front Thumbnail',null=True,blank=True,related_name='front_thumbnail_for_folders')
  middle_thumbnail_image = models.ForeignKey('Image',verbose_name='Middle Thumbnail',null=True,blank=True,related_name='middle_thumbnail_for_folders')
  back_thumbnail_image = models.ForeignKey('Image',verbose_name='Back Thumbnail',null=True,blank=True,related_name='back_thumbnail_for_folders')

class Image(models.Model):
  ...
  folder = models.ForeignKey(Folder,related_name='images',null=True)

class ImageRepresentation(models.Model):
  ...
  image = models.ForeignKey(Image, related_name="image_representations")

Given this model, when I delete an Image in the admin site, I would expect the ImageRepresentations associated with that Image to be deleted as well, and the Folder enclosing that Image to be left alone.

The admin site tells me that the enclosing Folder will be deleted as well. What can I do to get the desired behavior? I looked into delete cascade rules, but nothing I tried seemed to work.

Edited to add three foreign keys on Folder (the thumbnail image ones)… I totally overlooked those (obviously). There are no other relationships, honest.

  • 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-06-15T13:47:28+00:00Added an answer on June 15, 2026 at 1:47 pm

    When you create the ForeignKey, what gets deleted when the parent object is deleted is controlled by the on_delete parameter.

    By default, on_delete is set to models.CASCADE, which will delete children objects when the parent is deleted. None of the other configuration options can create the behavior you are reporting here.

    Do you have a Foreignkey from Folder to Image or ImageRepresentation? (folder thumbnail in your case)

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

Sidebar

Related Questions

I have three model classes that look as below: class Model(models.Model): model = models.CharField(max_length=20,
I use django, and have a lengthy models.py file. class Foo(models.Model): name = models.CharField()
Lets say I have three django model classes - lets call them A, B
Here's an example: If I have these classes class Author(models.Model): name = models.CharField(max_length=45) class
I currently have three Model classes: public class MarketReport { public MarketReportAbbrStores LISTOFSTORESUMMARY {get;
Have the following XML model <A></A> <B></B> <C></C> <D></D> Also have three classes class
I have three model classes: User. Entry. EntryLikes. As follows: public class User {
I have three models that are coming together to create one view model and
I have three models: class User include Mongoid::Document field :name, :type => String has_many
I have three models: class Book < ActiveRecord::Base has_many :collections has_many :users, :through =>

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.