有没有一种方法可以找到包含特定内容类型的页面(查询)。
可以说我有一个内容类型为的页面(注销)LogoutFormContent
。
如何找到具有LougOutFormContent作为内容类型的页面。
我试图做到这一点:
page = Page.objects.filter(logoutformcontent_set=True)
生成以下查询
SELECT * FROM `page_page` INNER JOIN `page_page_logoutformcontent`
ON (`page_page`.`id` = `page_page_logoutformcontent`.`parent_id`)
WHERE (`page_page_logoutformcontent`.`id` = 1)
除了page_page_logoutformcontent.id = 1
???,这几乎是正确的。
使用此功能找出哪些页面具有特定/特定的内容类型
def get_page_for_ct(request, ct):
ctp_page = Page.content_type_for(ct)
page = ctp_page.objects.filter(parent__language=request.LANGUAGE_CODE)
if not page:
raise ImproperlyConfigured(
'page not found: "%s" for language "%s" '
% (ct, request.LANGUAGE_CODE))
return page[0].parent
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句