gpt4 book ai didi

Django从多个表中检索数据

转载 作者:行者123 更新时间:2023-12-03 03:19:18 25 4
gpt4 key购买 nike

我有两个 MySQL 模型:

class registration(models.Model):
name = models.CharField(max_length=30)
email = models.EmailField()
password = models.CharField(max_length=30)
company = models.CharField(max_length=30)


class personal_details(models.Model):
reg = models.ForeignKey(registration)
job = models.CharField(max_length=30)
experience = models.IntegerField(default=0)

我想使用经验和公司作为关键字来过滤详细信息。我想从 HTML 页面的两个表中获取并显示详细信息(姓名、电子邮件、公司、工作、经验)。

最佳答案

details = personal_details.objects.filter(experience=1, 
reg__company="YourCompany").select_related()

{% for detail in details %}
Name: {{ detail.reg.name }}
Email: {{ detail.reg.email }}
Company: {{ detail.reg.company }}
Job: {{ detail.job }}
Experience: {{ detail.experience }}<br/>
{% endfor %}

关于Django从多个表中检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15812876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com