FeinCMS: простой поиск

Я пытаюсь создать простой поиск для моей страницы feinCMS. С помощью этого урока я создал поиск, который просматривает все заголовки страниц:

def get_results(query_string, search_fields):
    ''' Returns a query, that is a combination of Q objects. That combination
        aims to search keywords within a model by testing the given search fields.

    '''
    if len(query_string)>1:
        results = []
        query = None # Query to search for every search term        
        terms = normalize_query(query_string)
        for term in terms:
            results += Page.objects.filter(title__contains = term)
        return results

Но я не знаю, как я могу искать в различных типах контента.

Щас добавил markdowncontent_set = Page.content_type_for(MarkdownContent) но что я получу и как я могу просмотреть содержимое и проверить, содержит ли оно query_sring?

Редактировать:

Прямо сейчас мой код выглядит так:

def get_results(query_string, search_fields):
    ''' Returns a query, that is a combination of Q objects. That combination
        aims to search keywords within a model by testing the given search fields.

    '''
    if len(query_string)>0:
        results = []
        query = None # Query to search for every search term        
        terms = normalize_query(query_string)
        for term in terms:
            results += Page.objects.filter(title__contains = term)
            results += Page.objects.select_related("markdowncontent_set").filter(markdowncontent_set__content__contains = term)
        return list(set(results))

Возможно, не лучшее решение, но оно работает.

0 ответов

Другие вопросы по тегам