Skip to content

Django package for generating methods for toggling ManyToMany relationship entries in models.

License

Notifications You must be signed in to change notification settings

wencakisa/django-toggle-m2m

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Installation

pip install django_toggle_m2m

Usage in models

from django.db import models

from django_toggle_m2m.toggle import ToggleManyToMany


class Publication(models.Model):
    title = models.CharField(max_length=32)


class Article(models.Model, ToggleManyToMany):
    # ______________________^
    # Extend ToggleManyToMany class
    headline = models.CharField(max_length=256)
    publications = models.ManyToManyField(Publication)

    # Define M2M fields that are toggleable
    TOGGLEABLE_FIELDS = ('publications',)

Relation toggling

article = Article.objects.create(...)
publication = Publication.objects.create(...)

article.toggle_publications(instance=publication) # Will be added
article.toggle_publications(instance=publication) # Will be removed

Development

git clone https://github.com/wencakisa/django-toggle-m2m.git
pip install django_toggle_m2m

Interesting fact - https://code.djangoproject.com/ticket/20686

About

Django package for generating methods for toggling ManyToMany relationship entries in models.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages