'Multiple many-to-many relations through the same model in Django problem

i have a problem i don't know how to make multiple many-to-many relations through the same model.

This is my DB relations :

Db architecture

and this is my code, i want to know if what I did is right or not ?

class Projects(models.Model):

  Project_name = models.CharField(max_length=50)
  Poject_key = models.CharField(max_length=50)
  CITools = models.ForeignKey(CITools,null=True,on_delete=models.CASCADE)

  UsersO = models.ManyToManyField(User,through='OwnerShips') # for user Ownerships
  UserF = models.ManyToManyField(User,through='Favorites') # for user Favorites

This is my OwnerSHips class :

class OwnerShips(models.Model):
  user = models.ForeignKey(User,on_delete=models.CASCADE)
  project = models.ForeignKey(Projects,on_delete=models.CASCADE)

And this is my Favorites Class:

class Favorites(models.Model):
  user = models.ForeignKey(User,on_delete=models.CASCADE)
  project = models.ForeignKey(Projects,on_delete=models.CASCADE)


Solution 1:[1]

I don't think you can use foreign keys (ownerships and favorites) in Project before those classes are created.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Karthik Ronad