【发布时间】:2022-01-08 12:26:44
【问题描述】:
大家好!
Django 中的新手,很困惑,感谢帮助!我正在尝试创建一个表,例如:
| 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 |
拥有三个模型:
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)
组织模型的对象:
| organization_name |
|---|
| Organization 1 |
| Organization 2 |
AppealForm模型的对象:
| form_name |
|---|
| In written form |
| In oral form |
上诉模型的对象:
| 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 |
如何进行复杂查询,从 Appeal 模型中检索信息?并放置到上表的确切字段?:(
【问题讨论】:
标签: python-3.x django django-models django-views foreign-keys