title: best practice for Django junction table model structure
body: <p>I am using a junction table called &quot;UserRole&quot; for 2 different Django model called CustomUser and Role to specify many to many relationship from both of the table. My consideration is 1 customer can have multiple groups and 1 groups has multiple customers. So now I am little confused that my current model is OK or Do I need to modify</p>
  <pre><code>from django.db import models
  from django.contrib.auth.models import AbstractUser
  
  class CustomUser(models.Model):
      &quot;&quot;&quot;Model representing a User with some extended fields and email as username field&quot;&quot;&quot;
      USERNAME_FIELD = 'email'
      email = models.EmailField(max_length=100, unique=True)
      is_admin = models.BooleanField(default=False)
      permissions = models.ManyToManyField('Permission', related_name='+')
      # other fields goes here if needed
      REQUIRED_FIELDS = []
      
      def __str__(self):
          &quot;&quot;&quot;String for representing the Model object.&quot;&quot;&quot;
          return self.email
  
  class Role(models.Model):
      &quot;&quot;&quot;Model representing a Role&quot;&quot;&quot;
      
      name = models.CharField(max_length=200)
  
      # other fields goes here if needed
      class Meta:
          ordering = ['name']
  
      def __str__(self):
          &quot;&quot;&quot;String for representing the Model object.&quot;&quot;&quot;
          return self.name
  
  class UserRole(models.Model):
      &quot;&quot;&quot;Model representing a User's Role&quot;&quot;&quot;
      
      # ManyToManyField used because one user can have multiple roles and one role can have multiple users
      role_id = models.ManyToManyField(Role, on_delete=models.CASCADE, null=False,  verbose_name = 'Role', related_name='role')
      user_id = models.ManyToManyField(CustomUser, on_delete=models.CASCADE, null=False,  verbose_name = 'User', related_name='user_role')
      # other fields goes here if needed
  </code></pre>
  <p><strong>So my question is, the relationship is ok as I stated below?</strong></p>
  <pre><code>role_id = models.ManyToManyField(Role, on_delete=models.CASCADE, null=False,  verbose_name = 'Role', related_name='role')
  user_id = models.ManyToManyField(CustomUser, on_delete=models.CASCADE, null=False,  verbose_name = 'User', related_name='user_role')
  </code></pre>
  <p><strong>OR</strong></p>
  <pre><code>role_id = models.ForeignKey(Role, on_delete=models.CASCADE, null=False,  verbose_name = 'Role', related_name='role')
  user_id = models.ForeignKey(CustomUser, on_delete=models.CASCADE, null=False,  verbose_name = 'User', related_name='user_role')
  </code></pre>