【发布时间】:2020-10-26 17:47:30
【问题描述】:
我需要计算从我的 Flags 模型到我的 Post 模型的一些关系。现在我不明白如何在我的查询中查询 Post 模型名称,我了解如何查询 content_type_id 而不是 content_type (作为字符串)。我有这样的想法:
Q(models.Q(('app_label', 'App'), ('model', 'Post'))
但我不知道当时的语法是什么样子的,可以 smb.帮忙?
示例:
def post_list_most_bad_flags(request):
p_counter_query = Flags.objects.filter(content_type_id=12) # --> Want to replace this with content_type instead if content_type_id
counter = p_counter_query.count()
print(counter)
提前致谢
【问题讨论】: