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
2
votes
0 answers

Django m2m_changed not triggered with a custom through model

class SparePart(models.Model): name = models.CharField(max_length=255) description = models.TextField(blank=True, null=True) class SparePartOrderRelation(models.Model): sparepart = models.ForeignKey(SparePart) order =…
1
vote
1 answer

Many-to-many relation on User table in Django

I'm writing an app where I need to associate data with user pairs. For instance, each user pair will have a compatibility score associated with them, as well as many-to-many relationships such as artists that they have in common. I'm confused…
kasceled
  • 548
  • 1
  • 6
  • 18
1
vote
1 answer

Multiple M2M in django

I have two models in Django for a 2d map based game: class Block(models.Model): type = models.IntegerField() class ShopBuilding(models.Model): house_blocks = models.ManyToManyField(Block) street_blocks = models.ManyToManyField(Block) …
est
  • 11,429
  • 14
  • 70
  • 118
1
vote
1 answer

Django m2m queries, distinct Users for a m2m relationship of a Model

I have a model Model with a m2m field : user = .. fk user ... watchers = models.ManyToManyField(User, related_name="boardShot_watchers", null=True) How do i select all distinct Users involved in this watchers relationship for all my entries…
coulix
  • 3,328
  • 6
  • 55
  • 81
1
vote
1 answer

Django Many2Many query to find all `things` in a group of `categories`

Given these Django models: from django.db import models class Thing(models.model): name = models.CharField('Name of the Thing') class Category(models.model): name = models.CharField('Name of the Category') things =…
Bernd Wechner
  • 1,854
  • 1
  • 15
  • 32
1
vote
0 answers

How do I fix 'Message' instance needs to have a primary key value before this relationship can be used

When I try to add a Message from the admin pages I get the 'Message' instance needs to have a primary key value before this relationship can be used. Here is my models.py Message class... class Message(models.Model): """ Message as sent through…
1
vote
1 answer

[Django][DRF] How to get UNORDERED queryset from `.filter`?

first of all, I'm not a native at ENG so plz be patient my ENG skills or give me some advice. (FYI, Django ver 3.2.9 & DRF ver 3.12.4 with postgres ver 12.7) I'm writing API creating a post by using drf serializer. And I've been facing a problem…
SeojunYoun
  • 15
  • 5
1
vote
1 answer

How to handle Many-to-Many Relation in Django without an Intermediary Table?

I have inherited a weird table structure: class Customer(models.Model): account_number = models.CharField() class Subscription(models.Model): account_number = models.CharField() So the Customer and Subscription models are linked by their…
kloddant
  • 1,026
  • 12
  • 19
1
vote
0 answers

How can objects be reordered using django-sortedm2m?

A Collection object can contain several Item objects, and an Item object can be contained by several Collection objects. The items should be ordered in each collection. I am using django-sortedm2m: from sortedm2m.fields import…
1
vote
1 answer

Django makemigrations error on many to many relationship

What i want: Store information about running of group of people. What i did: from django.db import models from django.contrib.auth.models import User from datetime import timedelta class Route(models.Model): name =…
Naur
  • 81
  • 7
1
vote
1 answer

Prevent an entry in model from adding itself in many2many relationship

I want to prevent a user from following themselves in Django. The User model is defined like bellow: class User(AbstractUser): followers = models.ManyToManyField(‘self’, related_name=“following”, symmetrical= False) Changing save() method in…
UMR
  • 310
  • 4
  • 16
1
vote
1 answer

oneM2M: can an announced resource have a non announced resource as it's child

In oneM2M, can an announced resource have a non announced resource as it's child? I went through the documentations for oneM2M but can't find anywhere that clearly mentions this. For example, on my IN-CSE, I have created an announced AE (AE_ANNC),…
1
vote
1 answer

How to prepare a list for queryset (select2) from multiple m2m filed

One of my models has three columns which are M2M fields and each of these three M2M fields has different models. I want to get a dataset from this product attribute model as shown in the output SQU below. And this is the dataset I want to get as the…
Abzal Ali
  • 153
  • 1
  • 12
1
vote
1 answer

OneM2M: Changing MN-CSE configurations from IN-CSE

In oneM2M, I want to update the MN-CSE configurations by sending the command from IN-CSE to MN-CSE. How can I achieve this? My Approach: I am thinking of creating an AE on MN-CSE say CONFIG-AE. Every time I want to change anything, I will create a…
1
vote
1 answer

OneM2M: Notify IN-CSE of the new resources created on MN-CSE

In oneM2M, all the resources created on MN-CSE node are stored in the database on the node itself. I also want to notify IN-CSE of the new resources that are created on the MN-CSE and save them in the datatbase there. How can I achieve this? My…