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

Checking if any object in a queryset is in a ManyToMany relation

What I'd like to be able to do is similar to this pseudo-code - I'm just completely unaware of how to do this in python: user_groups = request.user.participant_groups.all() if group in user_groups not in self.object.settings.groups.all():…
user1428660
0
votes
1 answer

Filtering related objects for each item in a queryset

I have a model (we'll call it 'item') that can be tagged by users. Tags are specific to each user. So, for example, an item can have multiple tags by multiple users. I need to display a list of all items to a user. Within that list I'd like to be…
user1428660
0
votes
2 answers

Django saving to ManyToMany fields

I have a simple model class with 2 ManyToManyField fields like this: models.py class Folder(models.Model): user = models.ManyToManyField(User) asset = models.ManyToManyField(Asset) In my view, I know the user ID and the asset ID. Say the…
Derek Nutile
  • 211
  • 3
  • 10
0
votes
1 answer

Regroup list using ManyToManyField

I have model with ManyToManyField: class Action(models.Model): title = models.CharField('title', max_length=160) countries = models.ManyToManyField('Country', null=True, blank=True) class Country(models.Model): id =…
Cke4
  • 5
  • 4
0
votes
1 answer

ManyToManyField limit choices to dynamic foreign model

class TrialRun(models.Model): product = models.ForeignKey(NewProduct, verbose_name='Product',) class Component(models.Model): product = models.ForeignKey(NewProduct, verbose_name='Product',) class TrialIssue(models.Model): trialrun =…
user687673
  • 21
  • 1
  • 5
0
votes
1 answer

How to join 4 or 5 tables in Django

Say I have a few models in Django: class LevelZ(models.Model): title = models.CharField(_('yahoo z name'), max_length=255) is_display = models.BooleanField(_('Is displayed'), default=True) enable = models.BooleanField(_('is enable'),…
RD Andy
  • 5
  • 2
0
votes
3 answers

How to return string from model method

Using the following model, how would I return a string 'Baked fresh every day' if the BreadSchedule object had days_available equal to every day of the week? I want to be able to call this in my template (i.e. item.is_available_daily). class…
Patrick Beeson
  • 1,667
  • 21
  • 36
0
votes
1 answer

How to browse a manytomany field in create method openerp

I want to browse a many2many field but got this error: File "C:\Program Files (x86)\OpenERP 7.0\Server\server\openerp\addons\schoolem\schoolem_dispense_cours.py", line 39, in create AttributeError: '**browse_record_list' object has no…
levolutionniste
  • 424
  • 1
  • 6
  • 16
0
votes
1 answer

django, related_name, foreign key

I have to following code for the model in Django: class User(models.Model): username = models.CharField(max_length=50, unique=True) password = models.CharField(max_length=15) class Follows(models.Model): user =…
0
votes
2 answers

Form for ManyToMany relationship on Detail page

I have the following (simplified) models: class Idea(models.Model): tagline = models.TextField() class Lot(models.Model): address = models.CharField() ...other fields... ideas = models.ManyToManyField(Idea) I want to display a Lot…
0
votes
1 answer

Django managing a user access list with manytomany field

I'm using a ManyToManyField for an access_list on my site: class Projects(models.Model): access_list = models.ManyToManyField(User) and in my Views.py I'm saving the user who's created the Project into the access_list, then I display the users…
Jason B
  • 345
  • 1
  • 5
  • 13
0
votes
2 answers

django display ManyToManyField as a form field

I am trying to display a ManyToManyField in my template: class GvtCompo(models.Model): startDate=models.DateField(max_length=10, blank=False, null=False) endDate=models.DateField(max_length=10, blank=False, null=False) gvtCompo=…
rom
  • 3,592
  • 7
  • 41
  • 71
0
votes
2 answers

Need help with Django model design, ManyToManyField "through" an intermediate model and its implications for uniqueness

I have the following Django models: - class Company(models.Model): name = models.CharField(max_length=50) is_active = models.BooleanField(db_index=True) class Phase(models.Model): company = models.ForeignKey(Company) name =…
chefsmart
  • 6,873
  • 9
  • 42
  • 47
0
votes
1 answer

How can I get cascade deletion for ManyToManyFields?

I have a model with two ManyToManyFields referring to a Position model. When a Position instance is deleted, I would like to have the same behaviour in the admin as for a ForeignKey, i.e. cascade deletion + a message asking for confirmation with the…
jul
  • 36,404
  • 64
  • 191
  • 318
0
votes
1 answer

How can i filter a ManyToManyField if it contains a specified user?

I have a model like this: from django.contrib.auth.models import User class Post(models.Model): title = models.CharField(max_length=255) content = models.TextField() followers = models.ManyToManyField(User, null=True, blank=True) And…
Fredrik
  • 3
  • 1