相关字段查找无效:​​带有 content_type__name 的名称

Pro*_*eus 2 python django django-orm

我有以下...

@receiver(post_save)
def po_save(sender, instance, created, **kwargs):

    Event.objects.get(content_type__name=sender.__name__)
Run Code Online (Sandbox Code Playgroud)

这给出了错误:相关字段得到无效查找:名称

content_type__name但是我使用 content_type似乎有问题,name我做错了什么?

Iai*_*ton 5

来自Django 1.8的发行说明

django.contrib.contenttypes.models.ContentType 的 name 字段已被迁移删除并替换为属性。这意味着无法再通过此字段查询或过滤 ContentType。

  • 坝!然而,我确实发现 ``content_type__model`` 匹配类的 ``.__name__.lower()`` 以便工作。 (2认同)