Reorganizing many to many relationships in Django

Posted by Galen on Stack Overflow See other posts from Stack Overflow or by Galen
Published on 2010-05-23T19:52:32Z Indexed on 2010/05/23 20:01 UTC
Read the original article Hit count: 486

I have a many to many relationship in my models and i'm trying to reorganize it on one of my pages.

My site has videos. On each video's page i'm trying to list the actors that are in that video with links to each time they are in the video(the links will skip to that part of the video)

Here's an illustration


Flash Video embedded here

Actors...

Ted smith: 1:25, 5:30
jon jones: 5:00, 2:00

Here are the pertinent parts of my models

class Video(models.Model):
    actor = models.ManyToManyField( Actor, through='Actor_Video' )
    # more stuff removed

class Actor_Video(models.Model):
    actor = models.ForeignKey( Actor )
    video = models.ForeignKey( Video)
    time = models.IntegerField()

Here's what my Actor_Video table looks like, maybe it will be easier to see what im doing

id     actor_id    video_id    time (in seconds)
1        1             3        34
2        1             3        90

i feel like i have to reorganize the info in my view, but i cant figure it out. It doesn't seem to be possible in the template using djangos orm. I've tried a couple things with creating dictionaries/lists but i've had no luck. Any help is appreciated. Thanks.

© Stack Overflow or respective owner

Related posts about python

Related posts about django