I have the following entities:
- Videos
- Tags
- Relationship entity - VideoTags
Here's the schema:
class Tag(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100, unique=True)
class Meta:
db_table = u'tags'
class Video(models.Model):
guid = models.CharField(max_length=36, primary_key=True)
title = models.CharField(max_length=600)
tags = models.ManyToManyField(Tag, through='VideoTag')
class Meta:
db_table = u'videos'
class VideoTag(models.Model):
guid = models.CharField(max_length=36, primary_key=True)
tag = models.ForeignKey(Tag)
video = models.ForeignKey(Video)
weight = models.FloatField()
class Meta:
db_table = u'video_tags'
Now, this all works well when creating the entities. Now say I want to pull video by its Id and iterate over its tags.
When I do:
video = Video.objects.get(pk=1)
tags = video.tags.all()
I get in fact a list of Tag entities as they are related to the video and not the relationship entity VideoTag. I would like to access the video's tags and more importantly one of the extra fields on the relationship table - weight. I cannot do that since the tags property on video is of type Tag.
Thanks :)