def get_category(category_string, model=Category):
    """
    Convert a string, including a path, and return the Category object
    """
    model_class = get_cat_model(model)
    category = str(category_string).strip("'\"")
    category = category.strip('/')

    cat_list = category.split('/')
    if len(cat_list) == 0:
        return None
    try:
        categories = model_class.objects.filter(name=cat_list[-1], level=len(cat_list) - 1)
        if len(cat_list) == 1 and len(categories) > 1:
            return None
        # If there is only one, use it. If there is more than one, check
        # if the parent matches the parent passed in the string
        if len(categories) == 1:
            return categories[0]
        else:
            for item in categories:
                if item.parent.name == cat_list[-2]:
                    return item
    except model_class.DoesNotExist:
        return None
dataset/ETHPy150Open callowayproject/django-categories/categories/templatetags/category_tags.py/get_category/original