title: Django - how to order a sequence of videos within a topic?
body: <p>I am putting together a video library in django.  So far I have a few courses, each subgrouped to a topic, then each topic has 10-20 videos each.</p>
  
  <p>I would like to provide ordering for each grouping of videos within a topic.  So when a user goes through the lessons there is a specific sequence to the videos.</p>
  
  <p>My challenge is how to store the ordering of videos in my database backend (mysql) and further how to look up and retrieve the order?  I also want to have (previous) and (next) links so a user can easily click through the sequence.</p>
  
  <p>At first I was thinking I would just have a "sequence" int field on my video model, then look that up and simply find the next or previous one.  However, what if a number is skipped when entering the sequence?  I'd like to enforce the numbering in each sequence too.</p>
  
  <p>Here's some code so far:</p>
  
  <pre><code>class Video(models.Model):
      title = models.CharField(max_length=200)
      description = models.CharField(max_length=500, blank=True)
      topic = models.ForeignKey('VideoTopic')
      sequence = models.IntegerField(default=1, null=True, help_text="(Sequence within the topic)")
  
  class VideoTopic(models.Model):
      name = models.CharField(max_length=200, blank=True)
      description = models.TextField(blank=True)
      course = models.ForeignKey('course.Course')
  </code></pre>
  
  <p>While this somewhat fulfills the base requirements of sequencing, I don't see how to enforce the ordering, and I'm also having difficulty looking up my previous/next videos.</p>
  
  <p>I'm thinking I need to store sequence in a separate table, but I can't quite conceive how this should be done.  Something like:</p>
  
  <pre><code>class VideoSequence(models.Model)
      topic = models.ForeignKey('VideoTopic')
      sequence = models.IntegerField()
      video = models.ForeignKey('Video')
  </code></pre>
  
  <p>If I use the above separate table, how can I go about looking up the sequence in django?</p>