Exemplo n.º 1
0
def get_category_list(max_results=0, starts_with=''):
    if not max_results and not starts_with:

        categories = Category.objects.order_by("-likes")[:5]
        for category in categories:
            category.url = decode_url(category.name)
        return categories
    else:
        return get_suggested_category_list(max_results, starts_with)
Exemplo n.º 2
0
def get_suggested_category_list(max_results, starts_with):
    if starts_with:
        categories = Category.objects.filter(name__istartswith=starts_with)
    else:
        categories = Category.objects.all()

    if max_results > 0:
        if len(categories) > max_results:
            categories = categories[:max_results]
    for cat in categories:
        cat.url = decode_url(cat.name)
    return categories