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

ManyToManyFields as IntegerFields in Django admin interface

Assuming I have : class Product(models.Model): [...] class Basket(models.Model): content = models.ManyToManyField(Product, through="ProductQuantity") class ProductQuantity(models.Model): basket = models.ForeignKey(Basket) product =…
vmonteco
  • 14,136
  • 15
  • 55
  • 86
0
votes
2 answers

Python/Django - Get value of a ManyToManyField in a for tag

I can't get the image related value when I'm using {% for %} with the class Article. I tried with select_related, but I don't know how to define image to be correctly in displayed in the src="" attribute of my tag Is there a clean way to…
0
votes
1 answer

How to access ManyRelatedManager object attribute using mptt

What I got: class Category(MPTTModel): name = models.CharField(max_length=50, unique=True) slug = models.SlugField(unique=True) full_slug = models.CharField(max_length=256, null=True, blank=True) parent = TreeForeignKey('self',…
Kirill
  • 61
  • 1
  • 10
0
votes
1 answer

Django InlineAdmin for ManyToMany field which doesn't have an explicitly named through

I have two models, with ManyToMany relationships: App1: class Foo: fld = models.CharField(null=True, blank=True) App2: class Bar: foos = models.ManyToManyField(Foo, blank=True) Now, on the admin view of Bar, I'd like to present foos. I…
Csaba Toth
  • 10,021
  • 5
  • 75
  • 121
0
votes
1 answer

Bad for-loop in django with Groups model, ManyToMany field

I want to display 1 button in the for-loop, but i get as many buttons as many i have created groups. So.. when i created 3 groups where i'm one of the members, i got 3 buttons under every group i have. The problem is with this first loop in my code,…
Damian
  • 115
  • 4
  • 13
0
votes
1 answer

How to get data from ManyToManyField - Django

I have a problem with retrieving data from this ManyToManyField (users) of a model Event: class Event(models.Model): name = models.CharField(max_length=26) description = models.CharField(max_length=200) date = models.DateField() user…
worm2d
  • 159
  • 1
  • 2
  • 14
0
votes
1 answer

Adding users to the specific group in Django

I'm trying to add some users, in my Django project, to my created before group, but I know how to add to the specific group which I know the name and it's not dynamic. I would like that when I select a specific group, already add the next user. The…
Damian
  • 115
  • 4
  • 13
0
votes
1 answer

Making a reading list and confused about ManyToMany relationship between the models - Django

I am making an app where a user can save books to a "reading" list. I have created 2 models to connect to the custom User model(AbstractBaseUser) I have made. I am learning how to do this and have been reading the docs. For the book Model this is…
Corey Gumbs
  • 372
  • 6
  • 13
0
votes
0 answers

django form with multiple choice field with potentially infinite choices

I have a model with a many-to-many field that will expand as the user adds more entries for the model. In the form template if I use the conventional {{ form.field }} I get a multiple choice select as is expected, but the problem that will quickly…
E-rich
  • 9,243
  • 11
  • 48
  • 79
0
votes
1 answer

ManyToMany model field where choices change based on boolean

I'm relatively new to Django, and I've been trying to find a way to implement a ManyToMany field whose visible 'choices' within the UI change based upon a BooleanField found within the same model. For instance, suppose I have a model that represents…
0
votes
1 answer

How do I query objects of a ManyToManyField?(without through)

The given below are the models for a retail store. class Rack(models.Model): name = models.CharField(max_length=128) number = models.PositiveSmallIntegerField() categories = models.ManyToManyField(Category) class…
All Іѕ Vаиітy
  • 24,861
  • 16
  • 87
  • 111
0
votes
0 answers

Django: efficiently saving ManyToMany objects

I have got a Stop model and a Service model. They form a ManyToMany relationship with each other. This is done by using stops = models.ManyToManyField(Stop, related_name='services') inside the Service model. I would like to create new services and…
Marlyyy
  • 702
  • 1
  • 6
  • 17
0
votes
1 answer

Default Value Many To Many Field doesn't work, Django 1.8

I have following model: class Editor(models.Model): nombre = models.CharField(max_length=30) domicilio = models.CharField(max_length=50) #.... class Autor(models.Model): nombre = models.CharField(max_length=30) apellido =…
Carmoreno
  • 1,271
  • 17
  • 29
0
votes
3 answers

Django: NameError: name 'Category' is not defined

I'm practicing on Django and using some online tutorial to build a web blog. It went smoothly with the first project, yet when I tried the 2nd one, through developing the first view, there was this statement: categories =…
0
votes
1 answer

Inside Django class-base CreateView, how to init intermediate model

I have three models, PiItem is the interface of Pi and Items models by "through". Right now I want to create a new Items instance with new Pi instance and new PiItem instance inside Django CreatedView class. Somehow I keep getting error…