﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20686	Many-to-many related manager method: toggle()	Matt Deacalion Stevens		"My use case: on a few occasions I've needed to ‘**//toggle//**’ an M2M relation between two models, i.e. if the relation exists, it should be removed and if it doesn't it should be created.

{{{
#!div style=""font-size: 80%""
Usage – [http://git.io/NnNh0A using these models]:
  {{{#!python
  >>> a4
      <Article: Oxygen-free diet works wonders>
  >>> p2
      <Publication: Science News>
  >>> p2.article_set.all()
      [
          <Article: NASA finds intelligent life on Earth>,
          <Article: NASA uses Python>,
          <Article: Oxygen-free diet works wonders>,
      ]
  >>> a4.publications.toggle(p2) # the relation is removed
  >>> p2.article_set.all()
      [
          <Article: NASA finds intelligent life on Earth>,
          <Article: NASA uses Python>,
      ]
  >>> a4.publications.toggle(p2) # the relation is added
  >>> p2.article_set.all()
      [
          <Article: NASA finds intelligent life on Earth>,
          <Article: NASA uses Python>,
          <Article: Oxygen-free diet works wonders>,
      ]
  >>> p2.article_set.toggle(a4) # and… removed again (can be toggled from either model)
      [
          <Article: NASA finds intelligent life on Earth>,
          <Article: NASA uses Python>,
      ]
  }}}
}}}"	New feature	closed	Database layer (models, ORM)	dev	Normal	wontfix	toggle		Unreviewed	0	0	0	0	0	0
