Hi all!
New in Django, and confused, help is appreciated!
Have three models:
class Organization(models.Model):
organization_name = models.CharField(max_length=50)
class AppealForm(models.Model):
form_name = models.CharField(max_length=50)
class Appeal(models.Model):
organization = models.ForeignKey(Organization, on_delete=models.CASCADE)
appeal_form = models.ForeignKey(AppealForm, on_delete=models.CASCADE)
applicant_name = models.CharField(max_length=150)
Objects of Organization model:
| organization_name |
|---|
| Organization 1 |
| Organization 2 |
Objects of AppealForm model:
| form_name |
|---|
| In written form |
| In oral form |
Objects of Appeal model:
| organization | appeal_form | applicant_name |
|---|---|---|
| Organization 1 | In written form | First and Last name |
| Organization 1 | In oral form | First and Last name |
| Organization 1 | In oral form | First and Last name |
| Organization 2 | In written form | First and Last name |
| Organization 2 | In oral form | First and Last name |
I'm trying to create a table in the template, like:
| Organization | Total amount of appeals | Amount of written form appeals | Amount of oral form appeals |
|---|---|---|---|
| Organization 1 | 3 | 1 | 2 |
| Organization 2 | 2 | 1 | 1 |
The content in the table contents has to be retrieved from Appeal model, that is rendered to the template.
Question: How the query look like in views.py using Appeal model?