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

  • SEARCH
  • Home
  • 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 3232560
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:10:31+00:00 2026-05-17T17:10:31+00:00

Using the following related models (one blog entry can have multiple revisions): class BlogEntryRevision(models.Model):

  • 0

Using the following related models (one blog entry can have multiple revisions):

class BlogEntryRevision(models.Model):
    revisionNumber = models.IntegerField()
    title = models.CharField(max_length = 120)
    text = models.TextField()
    [...]

class BlogEntry(models.Model):
    revisions = models.ManyToManyField(BlogEntryRevision)
    [...]

How can I tell Django to delete all related BlogEntryRevisions when the corresponding BlogEntry is deleted? The default seems to be to keep objects in a many-to-many relation if an object of the “other” side is deleted. Any way to do this – preferably without overriding BlogEntry.delete?

  • 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-17T17:10:32+00:00Added an answer on May 17, 2026 at 5:10 pm

    I think you are misunderstanding the nature of a ManyToMany relationship. You talk about “the corresponding BlogEntry” being deleted. But the whole point of a ManyToMany is that each BlogEntryRevision has multiple BlogEntries related to it. (And, of course, each BlogEntry has multiple BlogEntryRevisions, but you know that already.)

    From the names you have used, and the fact that you want this deletion cascade functionality, I think you would be better off with a standard ForeignKey from BlogEntryRevision to BlogEntry. As long as you don’t set null=True on that ForeignKey, deletions will cascade – when the BlogEntry is deleted, all Revisions will be too.

    As Of Django 2.0

    The ForeignKey initializer now requires you to specify the on_delete parameter:

    from django.db import models
    from .models import MyRelatedModel
    
    
    class model(models.Model):
        related_model = models.ForeignKey(MyRelatedModel, on_delete=models.CASCADE)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume that I have following models: class ScoutBook(models.Model): troop = models.ForeignKey('Dictionary', limit_choices_to={'type' :
I have the following model in Django: class Bout (models.Model): fighter_1 = models.ForeignKey(Fighter, related_name=bout_fighter_1)
I have the following model structure below: class Master(models.Model): name = models.CharField(max_length=50) mounting_height =
I'm using jQuery with rails and have the following piece of code $('#related').html(<%= render
DUPLICATE: Using a Django custom model method property in order_by() I have two models;
My database has the following schema: class Product(models.Model): pass class Tag(models.Model): product = models.ForeignKey(Product)
Following is my model: class Story(models.Model): author = models.ForeignKey(User, related_name='author_id', default=1) source = models.ForeignKey(User,
Consider the following model: class FPModel(models.Model): # The user who created author = models.ForeignKey(auth.models.User,
This question is related to the this . I'm using the following to extract
I am using following class to show a grid like appearance with pagination on

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.