Questions tagged [m2m]

A type of relationship between entities of types A and B which associates a list of entities of type B to an entity of type A and vice versa. Types A and B may be the same type

A type of relationship between entities of types A and B which associates a list of entities of type B to an entity of type A and vice versa. Types A and B may be the same type.

See also:

271 questions
26
votes
2 answers

flask sqlalchemy many to many relationship with extra field

I have 2 tables: restaurants and foods, and a 3rd table restaurants_foods which stores the many to many relationship between the 2 tables restaurants_foods = db.Table('restaurants_foods', db.Column('restaurant_id', db.Integer,…
Olansile Ajibola
  • 381
  • 1
  • 3
  • 4
24
votes
3 answers

Django: Retrieving IDs of manyToMany fields quickly

I have the following model schema in Django (with Postgres). class A(Models.model): related = models.ManyToManyField("self", null=True) Given a QuerySet of A, I would like to return a dictionary mapping each instance of A in the QuerySet to a…
Noah Gilmore
  • 1,319
  • 2
  • 15
  • 24
20
votes
5 answers

django Cannot set values on a ManyToManyField which specifies an intermediary model. Use Manager instead

i am working on saving on the same form two tables - having a m2m relation. I don't succeed, my error persists with something like: Cannot set values on a ManyToManyField which specifies an intermediary model. Use Membership's Manager instead where…
dana
  • 5,168
  • 20
  • 75
  • 116
17
votes
4 answers

Django m2m form save " through " table

I'm having trouble in saving a m2m data, containing a 'through' class table. I want to save all selected members (selected in the form) in the through table. But i don't know how to initialise the 'through' table in the view. my code: class…
dana
  • 5,168
  • 20
  • 75
  • 116
17
votes
1 answer

Using Django's m2m_changed to modify what is being saved pre_add

I am not very familiar with Django's signals and could use some help. How do I modified the pk_set before the instance is saved? Do I have to return something to the signal caller (like the kwargs)? Or do I save the instance myself? As a…
thornomad
  • 6,707
  • 10
  • 53
  • 78
15
votes
1 answer

Django admin save not sending post_remove action with m2m_changed signal

I'm trying to get a many to many model to update when I save a related model. This should be possible using the m2m_changed signal (and it works! but not in the admin?) e.g. # i want the references field to update when related model is saved. # so…
Sam Simmons
  • 1,074
  • 8
  • 12
14
votes
6 answers

ManyToMany field not saved when using Django admin

I'm experiencing a weird problem which I hope someone in here may be able to shed some light on. I'm overriding the save() method of a model to add some values to a ManyToMany-field after running super(). My problem is that when I'm saving in Django…
kb.
  • 1,955
  • 16
  • 22
12
votes
4 answers

Django signal m2m_changed not triggered

I recently started to use signals in my Django project (v. 1.3) and they all work fine except that I just can't figure out why the m2m_changed signal never gets triggered on my model. The Section instance is edited by adding/deleting PageChild…
user543424
  • 121
  • 1
  • 3
12
votes
2 answers

Django 1.8 - Intermediary Many-to-Many-Through Relationship - What is the consequence of where 'ManytoManyField' is used?

An example Many-to-Many through relationship in Django: class First(models.Model): seconds = models.ManyToManyField(Second, through='Middle') class Middle(models.Model): first = models.ForeignKey(First) second =…
StringsOnFire
  • 2,726
  • 5
  • 28
  • 50
9
votes
1 answer

Django, in many to many relationship within the self class, how do I reference each other in terms of ORM?

class User(models.Model): name = models.CharField(max_length=100) age = models.IntegerField() gender = models.IntegerField() email = models.CharField(max_length=100) password = models.CharField(max_length=255) following =…
Jung
  • 219
  • 3
  • 10
8
votes
3 answers

List Field serializer giving 'ManyRelatedManager' object is not iterable error with M2M field

My models.py looks like this: class IP(models.Model): name = models.CharField(max_length=30, unique=True) address = models.CharField(max_length=50, unique=True) class IPGroup(models.Model): name = models.CharField(max_length=50,…
Amistad
  • 7,100
  • 13
  • 48
  • 75
8
votes
2 answers

celluloid-io or eventmachine with mosquitto loops

I'm building a small ruby program to run a connection to a MQTT server and subscribe to a channel. I'm using the mosquitto gem which is just a bridge for libmosquitto C library. I created a very simple implementation of a program that can run with…
Roland
  • 9,321
  • 17
  • 79
  • 135
7
votes
1 answer

django detect fixtures with m2m_changed signals

I am having trouble to figure out whether my signal handler is called during fixture loading or not. Most of my signal handlers receive an extra keyword raw when django load fixtures. However, this extra keyword only get passed through when handling…
Meitham
  • 9,178
  • 5
  • 34
  • 45
7
votes
1 answer

Editing both sides of M2M in Admin Page

First I'll lay out what I'm trying to achieve in case there's a different way to go about it! I want to be able to edit both sides of an M2M relationship (preferably on the admin page although if needs be it could be on a normal page) using any of…
DavidM
  • 127
  • 1
  • 1
  • 5
7
votes
1 answer

Display m2m field defined via 'through' in admin

I have the following model classes: class Category(models.Model): category = models.CharField('category', max_length=200, blank=False) class Book(models.Model): title = models.CharField('title', max_length=200, blank=False) categories =…
Asterisk
  • 3,534
  • 2
  • 34
  • 53
1
2 3
18 19