Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python _meta.get_all_field_names()中的GenericForeignKey名称错误_Python_Django - Fatal编程技术网

Python _meta.get_all_field_names()中的GenericForeignKey名称错误

Python _meta.get_all_field_names()中的GenericForeignKey名称错误,python,django,Python,Django,我有两种型号: class First(models.Model): name = models.CharField(max_length=50, default='n/a') content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey() def __

我有两种型号:

class First(models.Model):
    name = models.CharField(max_length=50, default='n/a')
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey()


    def __unicode__(self):
        return str(self.pk) + ' > ' + self.name


class Second(models.Model):
    name = models.CharField(max_length=50, default='n/a')
    r = generic.GenericRelation(First)

    def __unicode__(self):
        return str(self.pk) + ' > ' + self.name
当我这样做时:

from myapp.models import First
First._meta.get_all_field_names()
我得到:

['content_type', u'id', 'name', 'object_id', 'second']
因此,这里似乎将
content\u object
命名为
second
,而不是
GenericForeignKey
。这是预期行为吗


ps
Im使用Django 1.5.1。

A
GenericForeignKey
在后台使用两个字段;在这种情况下,它们是
content\u type
object\u id
since<代码>秒处于
秒。r

获取所有字段名称
返回所有字段名的列表,这些字段名是 此模型可能存在(包括反向关系名称)。这是 用于漂亮地打印调试输出(选项列表),因此 不包括仅限内部的字段名

在本例中,反向关系名称为
second
。是的,预期的行为