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

Make Django admin ManyToMany field filter_horizontal searchable on both sides?

Is there a way to make a ManyToMany field that uses filter_horizontal text searchable from both sides. By default the left side is searchable but the right is not.
acmisiti
  • 425
  • 1
  • 4
  • 17
3
votes
2 answers

How do I add together fields from a manytomanyfield in django?

I am creating a quote-generator in Django. I want to calculate the total of all items, insert it into a field, and save it. The models are as follows: from django.db import models from django.core.urlresolvers import reverse class…
3
votes
2 answers

How to limit manytomanyfields on a model?

I would like to check that I get not more than 3 relations set on a manytomanyfield. I tried on the clean method to do this : if self.tags.count()>3: raise ValidationError(_(u'You cannot add more than 3 tags')) But self.tags returns not the…
Tom
  • 257
  • 1
  • 3
  • 9
3
votes
1 answer

Extend Django's ManyToManyField with custom fields

I am working on a project that uses multiple ManyToManyFields, however, at this point I realize that I want the ManyToManyField to store some extra values (mostly automatically set), such as a timestamp for when the connection was created. I tried…
ponycat
  • 189
  • 1
  • 2
  • 12
3
votes
2 answers

rails_admin has_many through with extra field

I have 2 models. User and Project. And there is a many_to_many relation with and extra position field between them. I can't see that extra field on rails_admin edit page. How can add that field to form? user.rb has_many :projects, :through =>…
beydogan
  • 1,102
  • 1
  • 11
  • 23
3
votes
2 answers

Caching in Django's ManyToManyField

I struggle with some caching issue inside Django. So far I've seen this issue only when running testsuite. The problem is that sometimes (it seems that this happens always on second invocation of the code), Django does not update it's cache or it…
Michal Čihař
  • 9,799
  • 6
  • 49
  • 87
3
votes
1 answer

wadofstuff django serializers and manytomanyfields with "through" parameter

With wadofstuff django full serializers v. 1.1.0, I noticed that models with ManyToManyFields that specify a "through" model do not get serialized, even if you specify them explicitly with the relations parameter. Further, I noticed that…
Neil
  • 7,042
  • 9
  • 43
  • 78
3
votes
2 answers

Django multiple tag field

I'm trying to find a good tutorial for django how to create multiple tags in a model. For example: class Tag(models.Model): name = models.CharField() class Sample(models.Model): name = models.CharField() urlA = models.CharField() urlB …
Krizsán Balazs
  • 386
  • 1
  • 4
  • 18
2
votes
4 answers

Django model custom save with ManyToManyField problem

I know this question has been posted multiple times but I still couldn't find a definite answer to this problem. So, here I go: class Invoice(models.Model): program = models.ForeignKey(Program) customer = models.ForeignKey(Customer,…
Orengelo
2
votes
1 answer

how to use ManytoManyField in djangorestframework

i'm using djangorestframework. the models one meeting could have many participates. So i tried to use ManytoManyField of django: class Meeting(models.Model): name=models.CharField(max_length=100) …
whi
  • 2,685
  • 6
  • 33
  • 40
2
votes
2 answers

Saving to ManyToManyFields using ModelForm and ModelMultipleChoiceField

I've created a basic Django app that contains books/authors/publishers as per the Django Book - trying to use a ModelForm to create a means to modify existing books - the problem is that the 'authors' field is a ManyToManyField and when I choose a…
jonseager
  • 317
  • 2
  • 8
2
votes
1 answer

How to filter ManyToMany fields using django-filter

How can I filter a ManyToMany field with django-filter I would like to display an input field on a template where you can filter Student to get these results: all of the Students that speak English (Student.languages contains 'English') all of the…
ish
  • 75
  • 5
2
votes
1 answer

How do I work around 'circular import' in Django?

I'm getting a 'circular import' error when trying to makemigrations in Django. The two models in question are these. The error is being flagged on Team. from django.db import models from django.contrib.auth.models import User from…
CodeMonkey
  • 123
  • 7
2
votes
2 answers

DRF normalize nested serializer to download excel report using XLSXRenderer

I have a ManyToMany field in my models. In serializer, I am able to get the nested serialized data, but I want to normalize it. models.py class Authors(models.Model): name = models.CharField(max_length=20) class Mets: db_table =…
2
votes
0 answers

FieldDoesNotExist: User_balances has no field named 'None' - ManyToManyField

I am having a difficulty with a ManyToManyField and cannot seem to figure out how to fix this. When I access the ManyToManyField I get this error Models class AccountBalance(BaseModel): user = models.ForeignKey( User,…
James R.
  • 31
  • 1
  • 2