有没有办法找到包含特定内容类型的页面(查询)。
假设我有一个内容类型为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
???
答案 0 :(得分:0)
使用此功能查找哪个页面具有特定/给定内容类型
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