My question is pretty much the same as this question, except that ALL relationships should be many-to-many.
I have the following classes in my models.py (somewhat simplified):
class Profile(models.Model):
# Extending the built in User model
user = models.ForeignKey(User, unique=True)
birthday = models.DateField()
class Media(models.Model):
title = models.CharField(max_length=200)
description = models.TextField(max_length=2000)
class Role(models.Model):
name = models.CharField(max_length=50)
What I want is a junction table that looks something like this:
CREATE TABLE `media_roles` (
`media_id` bigint(20) unsigned NOT NULL,
`profile_id` bigint(20) unsigned NOT NULL,
`role_id` bigint(20) unsigned NOT NULL
)
- John Doe - Director, Writer, Producer
- Jane Doe - Executive Producer
- ...
This is what I've used so far:
class MediaRole(models.Model):
media = models.ForeignKey(Media)
user = models.ForeignKey(Profile)
role = models.ForeignKey(Role)
But isn't there any better way of doing this, not involving the creation of a separate class in the model?