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
6
votes
4 answers

Copy all fields of a django model instance

ok i think this is very basic, but since I am new to Django I don't know how to handle this. I need to copy an instance of a django-model. As explained here, there is a problem with copying ManyToMany relations. But the attachment…
Peter
  • 141
  • 1
  • 2
  • 5
6
votes
2 answers

Django Forms save_m2m

Hi I have a model which has 2 many to many fields in it. one is a standard m2m field which does not use any through tables whereas the other is a bit more complecated and has a through table. I am using the Django forms.modelform to display and…
John
  • 21,047
  • 43
  • 114
  • 155
6
votes
1 answer

django tastypie : Getting extra-values of a m2m relationships using intermediate model

I'm trying to use Tastypie with ManyToMany relationships using intermediate models (through keyword) (https://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships) I'm working with these models: class…
Solvik
  • 63
  • 1
  • 4
5
votes
2 answers

How to get the sum of numeric column in Ent

I have two tables: products and baskets, which have the M2M relation and the table name is basket_products. I am trying to get the specific basket-related products total price and quantity, but I am getting stuck again. How can I fix the following…
dsha256
  • 230
  • 1
  • 7
5
votes
1 answer

How to trigger an action after model and related m2m (groups) fields are saved?

How to do something after a Django user model save, including related changes to m2m fields like django.contrib.auth.models.Group? Situation I have a custom Django user model and want to trigger some actions after a user instance is - with related…
tombreit
  • 1,199
  • 8
  • 27
5
votes
1 answer

Django: cannot detect changes on many-to-many field with m2m_changed signal - auditing at model-level

I'd like to keep track on what field has changed on any model (i.e. audit at model level since it's more atomic, not at admin/form-level like what django and django-reversion can already do). I'm able to do that for any field using pre/post…
Edwin
  • 803
  • 1
  • 11
  • 19
5
votes
3 answers

How to get the related_name of a many-to-many-field?

I'm trying to get the related_name of a many-to-many-field. The m2m-field is located betweeen the models "Group" and "Lection" and is defined in the group-model as following: lections = models.ManyToManyField(Lection, blank=True) The field looks…
amann
  • 5,449
  • 4
  • 38
  • 46
4
votes
1 answer

Using SearchVectorFields on many to many related models

I have two models Author and Book which are related via m2m (one author can have many books, one book can have many authors) Often we need to query and match records for ingests using text strings, across both models ie: "JRR Tolkien - Return of the…
lys
  • 949
  • 2
  • 9
  • 33
4
votes
2 answers

how to check to ManyToManyField table to update m2m depend on a parent field django

I want to update m2m field depend on the its parent model for example: class ModelA(models.Model): status = models.BooleanField(default=True) status_of_product = models.ManyToManyField(Product, verbose_name='product') class…
art_cs
  • 683
  • 1
  • 8
  • 17
4
votes
1 answer

Django Display more fields in manytomany relationship on admin page

I have a page build model that has a manytomanyfield All i want is to display the other columns of the manytomany field model I have an image model with name and category fields and I want both to display on the admin page in an inline table with a…
fragmint
  • 322
  • 2
  • 6
4
votes
0 answers

Not required many-to-many relationship giving ValueError

I'm having an issue where I have a non required self many-to-many relationship that when saving a new object to an empty psql db gives me: Edit: This is when I'm admin saving, there is no view that saves the model. ValueError: "Video: Teste" needs…
EVolpert
  • 41
  • 3
4
votes
1 answer

How to select IoT M2M SIM card service

I've searched and nothing came up on here. I've developed an Remote Monitor for small wind turbines in Peru, using and Arduino Uno, Raspberry Pi and USB Modem. I want to try and reduce our monthly data costs (currently have a Claro peruvian SIM…
4
votes
1 answer

DRF - Nested Serialization Of m2m fields with through model

I am using a m2m field with a through model in DRF. Everything is working fine, EXCEPT when I try to nest the membership serializer. models.py class SweepStakes(models.Model): name =…
MrName
  • 2,363
  • 17
  • 31
4
votes
1 answer

Django Admin - Displaying Intermediary Fields for M2M Models

We have a Django app which contains a list of newspaper articles. Each article has a m2m relationship with both a "spokesperson", as well as a "firm" (company mentioned in the article). At the moment, the Add Article page for creating new Articles…
victorhooi
  • 16,775
  • 22
  • 90
  • 113
4
votes
1 answer

Django many to many relations on delete

I have the following models: class Branch(models.Model): releases = models.ManyToManyField(Release) class Release(models.Model): #fields What is the default django behavior when you delete a release object (in my case?) Will it delete all…
Apostolos
  • 7,763
  • 17
  • 80
  • 150
1
2
3
18 19