0

有没有办法找到包含特定内容类型的页面(查询)。

假设我有一个内容类型为的页面(注销)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???

4

1 回答 1

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
于 2013-10-04T13:05:16.477 回答