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

ManyToManyField using a select widget

I have a model that has a ManyToMany field. It came from a legal database with schema predefined. When I create a model form for that model it uses a Multi select field to render the ManyToMany field. The ones that created the db want a select field…
Apostolos
  • 7,763
  • 17
  • 80
  • 150
0
votes
1 answer

Did I break my DB while changing ManyToMany field in Django?

So I had a ForeignKey field and I needed to convert it to a ManyToManyField. When I ran the migration it gave this error: ValueError: Cannot alter field core_app.IndieTrack.contributors into core_app.IndieTrack.contributors - they are not…
Matt Payne
  • 198
  • 4
  • 15
0
votes
1 answer

ManyToManyField initialization in Django

I have following model: class Comment(models.Model): uuid = models.CharField(max_length=40, default='random') news = models.ForeignKey('News') user = models.OneToOneField(User, primary_key=True) # ForeignKey('User') text =…
Kamal Banga
  • 107
  • 1
  • 10
0
votes
1 answer

How to add an entry to ManyToManyField in Django?

I have the following models: class Vote(models.Model): cmt = models.ForeignKey(Comment) user = models.ForeignKey(User) vote_type = models.SmallIntegerField(default=0) # vote_type is +1 for upvote & -1 for downvote class…
0
votes
2 answers

Django ManytoMany retireving all objects that fulfill a condition simoultaneously

Using the Django models examples on querymaking (https://docs.djangoproject.com/en/1.8/topics/db/queries/): How can I select all the entries that have ALL of it's author's names starting with R using the filter function?
Marcox
  • 102
  • 10
0
votes
1 answer

Save m2m in FormView django

I'm trying to save a m2m field in a FormView. Here is my code: class ProductorPropietarioView(FormView): form_class = FormPropietario success_url = '/' template_name = 'productores/propietario.html' def form_valid(self,form): …
dfrojas
  • 673
  • 1
  • 13
  • 32
0
votes
1 answer

Django ValueError when trying to save ManyToMany Values from a Form

I get the error "" needs to have a value for field "dataset" before this many-to-many relationship can be used." when trying to assign values to a ManyToMany field in my views. I've looked at many related questions here on SO that say I must save my…
steph
  • 701
  • 2
  • 10
  • 30
0
votes
1 answer

Multiple ManyToMany in Django Admin

Problem relating to driving licences. A licence has a named person who is assiged multiple categories of driving skills. Each category of driving skill has a single renewal date and possible multiple related restrictions Name Lic Cat Renewal date…
Tommy Gibbons
  • 184
  • 1
  • 2
  • 12
0
votes
2 answers

Using the tables defined in the same models.py for list_display and populating the manyToMany fields of that table in admin forms

I am using Django 1.7, python 3.4 one of my models contains one class named Enterprise along with five other classes(Type, Products, etc.) each of which have a ManyToMany relation with Enterprise. class Enterprise(models.Model): …
sprksh
  • 2,204
  • 2
  • 26
  • 43
0
votes
1 answer

ManyToManyField with two possible data types

I'm trying to get a ManyToManyField working with a through model, which would look something like this: class DirectorCredit(models.Model): director = models.ForeignKey(Person, null=False) movie = models.ForeignKey(Movie, null=True) …
benwad
  • 6,414
  • 10
  • 59
  • 93
0
votes
1 answer

Django Multiple many-to-many through

I have two models A and B with an intermediary model C for holding a many-to-many relation using the through. as extra fields in C can have different values for the two same related objects of A and B, is it logically OK to do that? i.e. pair of…
pajooh
  • 1,916
  • 2
  • 18
  • 17
0
votes
1 answer

Django M2M self to relate an extend version of a table

I have two tables: Project and Contract. One project result in a contract. Plus, a contract could be extended leading to another contract related to the previous one. So I think I could use something like: contract =…
loar
  • 1,505
  • 1
  • 15
  • 34
0
votes
1 answer

Filtering django M2M field options with queryset

I want to filter the options that appear in a M2M field of a form using a queryset. I have read that limit_choices_to can only be used with ForeignKey. Is there something similar to limit_choices_to that can be applied to M2M? This is my…
DavidRguez
  • 1,070
  • 3
  • 12
  • 27
0
votes
1 answer

Django showing in a template a ManytoManyField that is into a Dictionary

The thing is quite simple but i don't know how to do it. I got the next models.py class ElementoDeRed(models.Model): IP_Address = models.CharField(max_length=200, primary_key= True) MAC_Address = models.CharField(max_length=200) …
David
  • 1
0
votes
2 answers

Many To Many Fields in Django

I'm new to Django and I have a question working with ManyToManyFields in Django with Admin. So I have two model classes. class Tag(models.Model): tag = models.CharField(max_length=100) def __str__(self): return self.tag class…
Miralem Cebic
  • 1,276
  • 1
  • 15
  • 28