Ordering in with Many-to-Many Relationships

937 views
Skip to first unread message

sethpomerantz

unread,
Sep 17, 2008, 2:51:15 PM9/17/08
to Django users
Hi,

I am building a simple web app that allows me to create a custom web
page of different quicktimes for presentation to clients and the like.
I have it working fine , however i'd like to add control over the
ordering of the quicktimes on the display pages. I am having a tough
time understanding how to implement ordering for a Many-to-Many
relationship, as each quicktime is used in multiple reels and would
require having a different value for its order. I would eventually
like to integrate this into the admin interface so i can quickly
define a specific order for a given reel.

Here is a striped down version of my models:

class Quicktime(models.Model):
name = models.CharField(max_length = 100)
order = models.IntegerField(blank = True, null = True)

def __unicode__(self):
return self.name

class Meta:
ordering = ('order',)

class Reel(models.Model):
name = models.CharField(max_length = 100)
quicktimes = models.ManyToManyField(Quicktime)

def __unicode__(self):
return self.name

thanks
Seth Pomerantz

TiNo

unread,
Sep 17, 2008, 3:24:31 PM9/17/08
to django...@googlegroups.com
If I understand you correctly, you (for example) have a quicktime1, in reel1 and reel2. In reel1 it is the first of, says 5 quicktimes, and in reel2 it is the third of 4?

The best solution that appears to me is an extra column in the intermediary table.
Here you could specify a field called order. 

To display you select everythong from the intermedirary model 'grouped_by=reel, order_by=order'.

Does this make any sense :D?
Reply all
Reply to author
Forward
0 new messages