Это отношение, подобное IMDB: у меня есть набор видео, и для каждого видео есть пользователи, зачисленные в видео.Что-то вроде -
For Video 1:
User 1 - Director
User 2 - Writer
...etc...
Ниже приведены модели, которые у меня есть -
class VideoInfo(models.Model):
title = models.CharField(max_length=256)
uploaded_by = models.ForeignKey('UserProfile')
credits = models.ManyToManyField('UserProfile', through='VideoCredit', blank=True, related_name='video_credits')
...
class VideoCredit(models.Model):
video = models.ForeignKey(VideoInfo)
profile = models.ForeignKey('UserProfile', blank=True, null=True)
name = models.CharField(max_length=100, blank=True)
position = models.ForeignKey(Position)
timestamp = models.DateTimeField(auto_now_add=True)
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
...
Для данного пользователя я хочу разделить титры видео по позициям.Что-то вроде -
For User A:
DIRECTOR
- Video 1
- Video 2
WRITER
- Video 1
- Video 3
...etc...
Как мне сделать что-то подобное в шаблоне -
{% for position in positions %}
<b>{{position}}</b>
{% for video in profile.videoinfo_set.filter(position = position) %} # ??
{{video}}
{% endfor %}
{% endfor %}
Или есть ли лучший способ выполнить то, что я пытаюсь сделать?Спасибо.