'In Django how to get the email address of a Foreign key user
I have a User model and a Project connected where the Project connects to User model with foreign key. How can I select the email address of the permitted user with raw query? (I don't want to use ORM).
models.py
class Project(models.Model):
def __str__(self):
return str(self.project)
project = models.TextField(max_length=150)
company_name = models.ForeignKey('Company', on_delete=models.CASCADE, default=1)
permitted = models.ForeignKey(User, on_delete=models.CASCADE, default=1)
I like to send emails to the permitted users but I need the email address of them. This is the raw query I tried:
SELECT COUNT(auth_user.id), ???
FROM pro_projects
LEFT JOIN auth_user
ON auth_user.id = pro_projects.permitted.id
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
