我有一个django.contrib.contenttypes.generic.genericForeignKeyField作为我模特的一员
但是,当我实例化模型,然后尝试从对象的元中获取字段时,它不会出现。在
例如:
class A(models.Model):
field2 = models.IntegerField(...)
field1 = generic.genericForeignKeyField()
a = A()
a._meta.fields ---> this does not show field1, but shows field2.
有人能告诉我为什么吗?在
谢谢!在
你为什么期望它呢?这不是一个真正的领域。它是一个虚拟字段,使用模型上的(real)
content_type
和object_id
字段进行计算。在但是您可以在
a._meta.virtual_fields
中看到它。在您没有正确设置泛型关系。阅读documentation:
最后,它一定是这样的:
相关问题 更多 >
编程相关推荐