Questions tagged [manytomanyfield]

Manytomanyfield is a field of a model class in Django that defines many-to-many relationship

Manytomanyfield is a field of a model class in Django that defines many-to-many relationship.

Quote from docs about manytomanyfield database representation:

Behind the scenes, Django creates an intermediary join table to represent the many-to-many relationship. By default, this table name is generated using the name of the many-to-many field and the name of the table for the model that contains it. Since some databases don’t support table names above a certain length, these table names will be automatically truncated to 64 characters and a uniqueness hash will be used. This means you might see table names like author_books_9cdf4; this is perfectly normal. You can manually provide the name of the join table using the db_table option.

See also:

526 questions
0
votes
1 answer

limit choices of manytomanyfield to a foreginkey

let's say i have these classes : models.py class Parent(models.Model): title = models.CharField(max_length=250) class Child(models.Model): parent = models.ForeignKey(Parent) title = models.CharField(max_length=250) class…
DjangoGuy
  • 103
  • 2
  • 13
0
votes
2 answers

cannot display work orders in an email

Hello I am trying to display work orders from my mysql database to show up in an email. However There is a problem because work_orders is a part of my Class Invoice manytomany field. This gives me this error. 'ManyRelatedManager' object has no…
0
votes
2 answers

Displaying a many-to-many fields

I seem to have a problem displaying work orders. in my app. The clients does not have the same problem so why does the work orders not show up. Actually it is as almost as a black space appears rather than text that should appear from my…
0
votes
0 answers

How to make a Django ManyToManyField point to multiple child models

What I would like to do is have something like this: class Parent(models.Model): class Meta: abstract=True class ChildA(Parent): pass class ChildB(Parent): pass class Test(models.Model): m2m =…
Joshua
  • 91
  • 3
0
votes
2 answers

Optimization of big queryset/context in django

I have to present a very complex page with a lot of data coming from 3 different tables related with ForeignKey and ManyToManyField... I was able to do what I want but performance is terrible and I'm stuck trying to find a better approach... here…
Attilio
  • 77
  • 1
  • 9
0
votes
0 answers

Django ManyToMany field related to itself in DRF

I have a Django Rest Framework and added the model Groups that I'm trying to relate back to itself, in a ManyToMany field called related_groups. The model changes and the makemigrations script created a new table called group_related_groups (Group…
0
votes
2 answers

How to add queryset to ManyToMany relationship?

I have following models: class EnMovielist(models.Model): content_ID = models.CharField(max_length=30) release_date = models.CharField(max_length=30) running_time = models.CharField(max_length=10) actress =…
Jin
  • 55
  • 1
  • 10
0
votes
1 answer

How to handle manytomany field with Scrapy

I want to use Scrapy with Django. My goal is link the actors field to the name field, but I don't know how to deal with Django manytomany. My database is MySQL (I'm not using djangoItem). models.py class Movies(models.Model): content_ID =…
Jin
  • 55
  • 1
  • 10
0
votes
1 answer

Django REST Framework ManyToMany Field Error

I am working with an existing database and wish to create a ManyToMany relationship between two tables. The abbreviated code is: class AddressSummary(models.Model): class Meta: managed = False db_table = 'addresses' …
vahndi
  • 1,055
  • 8
  • 16
0
votes
1 answer

Django Sort ManyToMany Field in A Nonsignificant Order

I have two models as below: class Stop(models.Model): """ Showing bus stops in İzmir. """ code = models.PositiveIntegerField( unique=True, primary_key=True, verbose_name="Code" ) label =…
Eray Erdin
  • 2,633
  • 1
  • 32
  • 66
0
votes
1 answer

How can I get an asymmetric many-to-many self-relationship to show up for both parties in a Django restful response?

I currently have 2 relevant classes in my model: A UserProfile class and a FriendInvite class in models.py class UserProfile(models.Model): user = models.OneToOneField(User) username = models.TextField() friends =…
Max Candocia
  • 4,294
  • 35
  • 58
0
votes
1 answer

Django models returning updated values in save() and not old values in M2M instance

This is my model class Userlist(models.Model): username = models.CharField(max_length=20) class Mailinglist(models.Model): users = models.ManyToManyField(Userlist, blank=True) def __init__(self, *args, **kwargs): …
renno
  • 2,659
  • 2
  • 27
  • 58
0
votes
1 answer

Django: Limit the number of returned ManyToMany objects

I am using django.core.serializers to serialise my Queryset and then return it as JSON later on. from django.core import serializers from .models import MyModel def a_view(request): objects = MyModel.objects.all() …
Shin
  • 678
  • 3
  • 12
  • 22
0
votes
0 answers

Using views to show model objects

I am new to Django and wanted to know how to retrieve a record from django database. Since I am learning, I don't know if model created by me is correct or not. model.py class ProductCategory(models.Model): prodname =…
Ajay k
  • 1
  • 2
0
votes
2 answers

Django TypeError unsupported operand type(s) for +: 'dict' and 'int'

I created a through model so I can add an order field to the m2m field but I am having problems auto incrementing the order field via def number() below. When I add an object, I get TypeError unsupported operand type(s) for +: 'dict' and 'int' and…
bayman
  • 1,579
  • 5
  • 23
  • 46