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

Django Admin: Many-to-Many listbox doesn't show up with a through parameter

I have the following models: class Message(models.Model): date = models.DateTimeField() user = models.ForeignKey(User) thread = models.ForeignKey('self', blank=True, null=True) ... class Forum(models.Model): name =…
Neil
  • 7,042
  • 9
  • 43
  • 78
10
votes
4 answers

How to check the type of a many-to-many-field in django?

How can you check the type of a many-to-many-field in django? I wanted to do it this way: import django field.__class__ == django.db.models.fields.related.ManyRelatedManager This doesn't work, because the class ManyRelatedManager can't be…
amann
  • 5,449
  • 4
  • 38
  • 46
10
votes
2 answers

Alter model to add "through" relationship to order a ManytoMany field - Django 1.7 migration modification

I am trying to add an order to a ManyToMany field that I created a while ago. I basically want to order pictures in collections of pictures. I am running on Django 1.7, so no more South migrations (I was trying to follow this tutorial:…
Alb Dum
  • 1,121
  • 3
  • 11
  • 26
9
votes
1 answer

Limiting a Django form's ManyToManyField queryset in a formtools wizard based on selection on previous form

I'm using a SessionWizardView from django-formtools to construct a two-form wizard. The challenge I'm facing is that I need to reference the input from the first form to limit the available querysets on the second form. To make it more interesting,…
9
votes
1 answer

Ordered ManyToManyField that can be used in fieldsets

I've been working through an ordered ManyToManyField widget, and have the front-end aspect of it working nicely: Unfortunately, I'm having a great deal of trouble getting the backend working. The obvious way to hook up the backend is to use a…
c_harm
8
votes
4 answers

Getting objects.all() reverse() or descending order

In Django, calling object.manytomany.all().reverse(), and its template equivalent, object.manytomany.all.reverse, don't seem to work for many-to-many relationships. How do I reverse a list of results of a many-to-many relationship?
gabor
  • 4,281
  • 8
  • 24
  • 20
8
votes
1 answer

TypeError: products() got multiple values for argument 'pk'

models.py I have two models with manytomany field which makes me confuse everytime. class Product(models.Model): product_name = models.CharField(max_length=32) quantity = models.IntegerField() remarks =…
Ian
  • 321
  • 6
  • 16
8
votes
1 answer

django display content of a manytomanyfield

I started using django framework just a few days ago and i desperately need some help with my application. It consists of client,project,admin,and admin payment classes where the admin_payment holds the ids of the admins and projects among other…
Thordin9
  • 379
  • 1
  • 4
  • 14
8
votes
0 answers

Django - Migrate ManyToMany to through

I have a model that looks like this: class Assignment(models.Model): """An assignment covers a range of years, has multiple coders and one specific task""" title = models.CharField(blank=True, max_length=100) start_date =…
LukasKawerau
  • 1,071
  • 2
  • 23
  • 42
8
votes
4 answers

Django (1.2) Forms: ManyToManyField Help Text

I hope I'm wrong, but it looks to me like the only way to have no help_text for a ManyToManyField is write an __init__ method for the form and overwrite self.fields[fieldname].help_text. Is that really the only way? I prefer to use…
Zach
  • 18,594
  • 18
  • 59
  • 68
8
votes
2 answers

Django: Cannot resolve keyword '' into field. Choices are:

I am having this weird problem accessing ManyToManyField. I have following models. class Link(models.Model): title = models.CharField(max_length = 200) url = models.URLField(unique = True) tags = models.ManyToManyField(Tag) …
Asur
  • 1,949
  • 4
  • 23
  • 41
8
votes
2 answers

Django: Is there a way to have the "through" model in a ManyToManyField in a different app to the model containing the ManyToManyField?

Lets say I have two django apps: competitions - which will handle competition data entries - which will handle functionality relating to entering competitors into competitions In the competitions app I have a model which represents a section of a…
Monika Sulik
  • 16,498
  • 15
  • 50
  • 52
7
votes
1 answer

Way to allow for duplicate many-to-many entries in Python/Django

I have the following Django model: class Icon(models.Model): name = models.CharField(max_length=200,null=False,blank=False) class Post(models.Model): icons = models.ManyToManyField(Icon) When I write the following code: post = Post() icons…
ryankicks
  • 73
  • 1
  • 3
7
votes
3 answers

Django: "limit_choices_to" doesn't work on ManyToManyField

I am running Django 1.1 and cannot get the "limit_choices_to" option for my ManytoManyField to work. I have two models: class MemberPhoto(ImageModel): title = models.CharField(_('title'), max_length=255, blank=True, null=True) caption …
Kyle Duncan
  • 283
  • 4
  • 12
7
votes
2 answers

Django Rest Framework Many to Many field related to itself

I have an AngularJS project that used Django as a framework through the Django Rest Framework (DRF). I've created a Group model and set up a serializer class for it, however I want to now establish a new field on that model called related_groups,…
1
2
3
35 36