I have 4 models in my project. Which are :
class Company(Group):
address_1 = models.CharField(max_length = 300, blank = True, null = True)
web_site = models.URLField(blank = True, null = True)
office_number = models.CharField(max_length = 20, blank = True, null = True)
class Person(models.Model):
user = models.ForeignKey(User)
company = models.ForeignKey(Company)
class Project(models.Model):
name = models.CharField(max_length = 100)
person = models.ManyToManyField(User, through = 'UserProject')
class UserProject(models.Model):
user = models.ForeignKey(User)
project = models.ForeignKey(Project)
is_owner = models.BooleanField(default = False)
In a view I would want to get
- All the projects related to the request.user
- The companies that are working on those projects
- and the employees of those companies
I have tried writing some code but the queries are not precise. Help would be appreciated!
I have pondered and used some of the solutions enlisted above, but nothing was exact to what I was looking for. For me the following piece of code works well