Django removing object from ManyToMany relationship

前端 未结 3 651
遇见更好的自我
遇见更好的自我 2020-12-12 16:47

How would I delete an object from a Many-to-Many relationship without removing the actual object?

Example:

I have the models Moods

3条回答
  •  攒了一身酷
    2020-12-12 17:14

    my_mood.interests.remove(my_interest)
    

    Django's Relations Docs

    Note: you might have to get an instance of my_mood and my_interest using Django's QuerySet API before you can execute this code.

提交回复
热议问题