manytomanyfield

Django MTMField: limit_choices_to = other_ForeignKeyField_on_same_model?

I've got a couple django models that look like this: from django.contrib.sites.models import Site class Photo(models.Model): title = models.CharField(max_length=100) site = models.ForeignKey(Site) file = models.ImageField(upload_to=get_site_profile_path) def __unicode__(self): return self.title class Gallery...

In Django, how do you retrieve data from extra fields on many-to-many relationships without an explicit query for it?

Given a situation in Django 1.0 where you have extra data on a Many-to-Many relationship: class Player(models.Model): name = models.CharField(max_length=80) class Team(models.Model): name = models.CharField(max_length=40) players = models.ManyToManyField(Player, through='TeamPlayer', related_name='teams') class TeamPlayer(models...

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, related_name='invoices') participants = models.ManyToManyField(Participant, related_name='par...

Django : save a new value in a ManyToManyField

Hi, I gave details on my code : I don't know why my table is empty (it seems that it was empty out after calling save_model, but I'm not sure). class PostAdmin(admin.ModelAdmin): def save_model(self, request, post, form, change): post.save() # Authors must be saved after saving post print form.cleaned_data[...

Querying django ManyToMany

I have got Foo <=> FooGroup <=> Bar relation, where <=> stands for ManyToMany field. How do I retrieve all the Foos for a specific Bar instance? ...

Django - ManyToMany

I'm making a game link site, where users can post links to their favorite web game. When people post games they are supposed to check what category the game falls into. I decided to allow many categories for each game since some games can fall into many categories. So the question is, how do I handle this in my view? And how can I...

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 = models.CharField(max_length=50) is_active = models.BooleanField(db_index=True) class Proces...

How can i use ManyToManyRawIdWidget outside admin?

Im new to django and I would like to know how could i use the ManytoManyRawId widget outside admin. I've tried different ways but still don't work. Help would be really much appreciated. ...

How can I sort by the id of a ManyToManyField in Django?

I've got a ManyToManyField in a user object and it's used to map the users that user is following. I'm trying to show a subset list of who they have most recently followed. Is there a trick in .order_by() that will allow me to sort by the id of the ManyToManyField? The data is there, right? # (people the user is following) following = m...

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 competition: class Division(models.Model): competition = models.ForeignKey(Competit...

What is the best means to achieve efficient many-to-many scanning with Django models?

I have a many to many relationship in Django similar as this: class Account ( models.Model ): name = models.CharField( max_length = 30 ) user = models.ForeignKey( User, null = True, blank = True ) class Publisher ( models.Model ): publisherID = models.BigIntegerField( ) name = models.CharField( max_length = 30 ) lastRequested...

My Django manytomany fields are all marked unique, is there an option to remove this?

Given a model like this: class A(models.Model): def __unicode__(self): return "%d"%self.id class B(models.Model): a_set = models.ManyToManyField(A) def __unicode__(self): return "%d"%self.id Then the following series of operations demonstrates my problem: In [1]: a1=A() In [2]: a1.save() In [3]: a1 Out[3...

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 current updates... only saved objects. Do you have an idea to access to them ? Thanks ...

Django, get fully serialized object. All properties from many to many relationships

I'm looking for a way to serialize an entire object with all of it's relationships. I seem to be only able to get the primary key from the serializer now. This is my model: class Action(models.Model): name = models.CharField('Action Name', max_length=250, unique=True) message = models.TextField('Message', blank=True, null=True...

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 found. But if i do field.__class__ the output is django.db.models.fields.related.ManyRelatedManager...

Django Admin: how to get the admin widget to appear for both models in a many-to-many relationship?

In the Django docs, it says: By default, admin widgets for many-to-many relations will be displayed on whichever model contains the actual reference to the ManyToManyField I want the widget to appear on the add/change page for both models in the relationship. How do I do that? ...

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

Hi All, 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 = models.CharField(max_length=24) messages = models.ManyToManyField(Message, through="M...

manyToManyField question

Hay guys, I'm writing a simple app which logs recipes. I'm working out my models and have stumbled across a problem My Dish models needs to have many Ingredients. This is no problem because i would do something like this ingredients = models.ManyToManyfield(Ingredient) No problems, my dish now can have many ingrendients. However, t...

Django self-recursive ManyToManyField filter query

Hi, I have a model like so: class Activity(models.Model): title = models.CharField(max_length=200) summary = models.TextField(null=True, blank=True) tasks = models.ManyToManyField('self', symmetrical=False, null=True, blank=True) It works like this, an activity can be linked to itself and the parent activity is call...

Ordered ManyToManyField that can be used in fieldsets

Hey all, 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 through table keyed off a model with ForeignKeys to both sides of the relationship ...