Skip to main content

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

Project description

django-toggle-m2m

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-toggle-m2m, version 0.0.6
Filename, size File type Python version Upload date Hashes
Filename, size django_toggle_m2m-0.0.6-py2.py3-none-any.whl (3.5 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size django_toggle_m2m-0.0.6.tar.gz (3.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page