Many to Many Ordered List

124 views
Skip to first unread message

chris....@gmail.com

unread,
Jun 19, 2006, 3:53:42 PM6/19/06
to Django users
Hi There,

I just released my first pubic facing Django site, and have run into a
design problem. It's a music blog / band site at
http://www.victimoftime.com

Something I didn't consider when I was building it (I'm the tech guy,
others are the content people) is that at a given concert, the bands
play in a specific order, and that order is important.

I chose to use Many to Many relationships for concerts and bands, so
that I can easily give a view of a particular concert, with the bands
involved, click on a band, and get a listing of upcoming shows, etc.

The problem is, how can I preserve the many to many relationship, but
have a specific order for the bands? Any ideas?

If nothing else, I'm probably going to include a field for band order
that's just a string. Then use some regexes to figure out which band
is which from the list.

Thanks in advance.

Chris

James Bennett

unread,
Jun 19, 2006, 3:59:40 PM6/19/06
to django...@googlegroups.com
On 6/19/06, chris....@gmail.com <chris....@gmail.com> wrote:
> The problem is, how can I preserve the many to many relationship, but
> have a specific order for the bands? Any ideas?

You should be able to take the QuerySet of bands for the concert and
tack on an 'order_by()' to sort by whatever field you like on the band
model.

--
"May the forces of evil become confused on the way to your house."
-- George Carlin

chris....@gmail.com

unread,
Jun 19, 2006, 4:19:33 PM6/19/06
to Django users

James Bennett wrote:
> On 6/19/06, chris....@gmail.com <chris....@gmail.com> wrote:
> > The problem is, how can I preserve the many to many relationship, but
> > have a specific order for the bands? Any ideas?
>
> You should be able to take the QuerySet of bands for the concert and
> tack on an 'order_by()' to sort by whatever field you like on the band
> model.

That's a good idea, except the bands will be in a different order
depending on the show they're in. Somedays Stevie Wonder is the
headliner, other days he's just opening for Prince.

Thanks for the idea. I think this might be a complicated thing to
handle, without an easy answer.

Chris

yml

unread,
Jun 19, 2006, 5:18:32 PM6/19/06
to Django users
I would handle this kind of situation by adding an intermediate class
AttributeOfTheLink. I don't know if this is a good practice but I think
it will do the tricks.

Let me know if you find something better.

Yann

yml

unread,
Jun 19, 2006, 5:22:34 PM6/19/06
to Django users
Here it is a link that details the solution a bit more:

-
http://www.djangoproject.com/documentation/models/m2m_intermediary/

Yann

Ivan Manolov

unread,
Jun 19, 2006, 6:16:32 PM6/19/06
to Django users
I am having a similar problem here.
having read the m2m_intermediary/ wiki page, I still cant wrap my head
around the idea of displaying a multiple select dropdown list of
related objects on the admin side.

Reply all
Reply to author
Forward
0 new messages