gpt4 book ai didi

python - usera._meta.get_all_field_names() 中的变量比模型中的变量更多

转载 作者:太空宇宙 更新时间:2023-11-03 18:47:31 25 4
gpt4 key购买 nike

当我尝试在模板中打印 usera._meta.get_all_field_names() 中的所有变量时,它给了我比预期多 2 个变量,我不知道为什么。

型号:

class Clovek(models.Model):
user=models.OneToOneField(User)
ulice=models.CharField(max_length=100, blank=True, null=True)
cislo_popisne=models.CharField(max_length=100, blank=True, null=True)
mesto=models.CharField(max_length=100, blank=True, null=True)
psc=models.CharField(max_length=100, blank=True, null=True)
telefonni_cislo=models.CharField(max_length=100, blank=True, null=True)
zdravotni_pojistovna=models.CharField(max_length=100, blank=True, null=True)

模板中的输出:

['cislo_popisne', 'id', 'mesto', 'psc', 'student', 'telefonni_cislo', 'ucitel', 'ulice', 'user', 'zdravotni_pojistovna']

最佳答案

您很可能有另一个模型(或多个模型),其外键为 Clovek,且具有反向关系名称 ucitelstudent

get_all_field_names() documentation非常清楚:

Returns a list of all field names that are possible for this model (including reverse relation names)

关于python - usera._meta.get_all_field_names() 中的变量比模型中的变量更多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19166251/

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