0

I have a model with two ManyToManyFields referring to a Position model. When a Position instance is deleted, I would like to have the same behaviour in the admin as for a ForeignKey, i.e. cascade deletion + a message asking for confirmation with the list of the objects that will be deleted.

How can I do that?

class Task(models.Model):    
    start_positions = models.ManyToManyField(Position, related_name='start_pos')
    end_positions = models.ManyToManyField(Position, related_name='end_pos')
    # more stuff

EDIT

I'm aware of this question: Django - Cascade deletion in ManyToManyRelation, but it has no proper answer.

Community
  • 1
  • 1
jul
  • 36,404
  • 64
  • 191
  • 318

1 Answers1

0
class Task(models.Model):    
    start_positions = models.ManyToManyField(
        Position, 
        related_name='start_pos', 
        on_delete=models.CASCADE
        )
    end_positions = models.ManyToManyField(
        Position, 
        related_name='end_pos', 
        on_delete=models.CASCADE
        )
catherine
  • 22,492
  • 12
  • 61
  • 85