Django - Cascade deletion in ManyToManyRelation

前端 未结 4 583
陌清茗
陌清茗 2020-11-29 10:23

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

class BlogEntryRevision(models.Model):
    revisionNumber = models.IntegerFi         


        
4条回答
  •  粉色の甜心
    2020-11-29 10:48

    Simply use the clear() method to remove related objects since Django uses a through model to specify the relationships the clear method removes all related BlogEntryRevision

    be = BlogEntry.objects.get(id=1)
    be.blogentryrevision_set.clear()
    

提交回复
热议问题