Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wencakisa/django-toggle-m2m
Django package for generating methods for toggling ManyToMany relationship entries in models.
https://github.com/wencakisa/django-toggle-m2m
django django-orm many-to-many python-3 toggle
Last synced: 26 days ago
JSON representation
Django package for generating methods for toggling ManyToMany relationship entries in models.
- Host: GitHub
- URL: https://github.com/wencakisa/django-toggle-m2m
- Owner: wencakisa
- License: mit
- Created: 2019-06-27T09:44:10.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T05:49:11.000Z (almost 2 years ago)
- Last Synced: 2024-09-29T17:03:43.608Z (about 1 month ago)
- Topics: django, django-orm, many-to-many, python-3, toggle
- Language: Python
- Homepage: https://pypi.org/project/django-toggle-m2m/
- Size: 17.6 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [django-toggle-m2m](https://pypi.org/project/django-toggle-m2m/)
## Installation
```bash
pip install django_toggle_m2m
```## Usage in models
```python
from django.db import modelsfrom 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
```python
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
```bash
git clone https://github.com/wencakisa/django-toggle-m2m.git
pip install django_toggle_m2m
```---
*Interesting fact* - https://code.djangoproject.com/ticket/20686