def get_category_lists(init_kwargs=None, additional_parents_aliases=None, obj=None):
    """Returns a list of CategoryList objects, optionally associated with
    a given model instance.

    :param dict|None init_kwargs:
    :param list|None additional_parents_aliases:
    :param Model|None obj: Model instance to get categories for
    :rtype: list
    :return:
    """
    init_kwargs = init_kwargs or {}
    additional_parents_aliases = additional_parents_aliases or []

    parent_aliases = additional_parents_aliases
    if obj is not None:
        ctype = ContentType.objects.get_for_model(obj)
        cat_ids = [
            item[0] for item in
            get_tie_model().objects.filter(content_type=ctype, object_id=obj.id).values_list('category_id').all()
        ]
        parent_aliases = list(get_cache().get_parents_for(cat_ids).union(additional_parents_aliases))
    lists = []

    aliases = get_cache().sort_aliases(parent_aliases)
    categories_cache = get_cache().get_categories(aliases, obj)

    for parent_alias in aliases:
        catlist = CategoryList(parent_alias, **init_kwargs)  # TODO Burned in class name. Make more customizable.
        if obj is not None:
            catlist.set_obj(obj)
        # Optimization. To get DB hits down.
        cache = []
        try:
            cache = categories_cache[parent_alias]
        except __HOLE__:
            pass
        catlist.set_get_categories_cache(cache)
        lists.append(catlist)

    return lists
dataset/ETHPy150Open idlesign/django-sitecats/sitecats/toolbox.py/get_category_lists