gpt4 book ai didi

django:如何从 ContentType 实例中获取对象

转载 作者:行者123 更新时间:2023-12-01 09:14:50 25 4
gpt4 key购买 nike

我想从 ContentType 实例中获取对象的查询集,然后能够过滤它们。从文档中,可以到 get()一个对象使用:

ct.get_object_for_this_type(**kwargs)

如何制作类似的 filter()例如?

最佳答案

由于您拥有 ContentType 实例,您可以执行 ct.model_class()获取模型类,然后像往常一样使用它。

model_class = ct.model_class()
model_class.objects.filter(**kwargs)

关于django:如何从 ContentType 实例中获取对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47486414/

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