usera._meta.get_all_field_names()中的变量多于模型中的变量

时间:2013-10-03 18:14:06

标签: python django django-models

当我尝试在模板中打印来自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']

1 个答案:

答案 0 :(得分:1)

您很可能拥有另一个带有[{1}}外键的模型(或多个模型),其反向关系名称为Clovekucitel

get_all_field_names() documentation非常清楚:

  

返回此模型可能的所有字段名称的列表   (包括反向关系名称

相关问题