title: Python - How do I get classes that rely on each other to be defined in the same file?
body: <p>I have the following code used in Django:</p>
  <pre><code>from django.db import models
  from django.contrib.auth.models import AbstractUser
  
  
  # Create your models here.
  
  class User(AbstractUser):
      groups = models.ManyToManyField(group)
  
  class group(models.Model):
      owner = models.ForeignKey(User, on_delete=models.CASCADE, related_name=&quot;course&quot;, null=True)
      name = models.CharField(max_length=50)
      description = models.CharField(max_length=300)
  
  
      def __str__(self):
          return self.name
  </code></pre>
  <p>I made this code to get a user model in django that allows for more fields. However, the new user class requires the group field since a user can join many groups. This is causing an error since the group is defined after class. What do I do to fix this issue? What I really need is just a way to add extra fields to the default User class so I tried it like so from another SE post.</p>