def get_latest_objects_by_category(category, app_label, model_name, set_name, date_field='pub_date', num=15):
    m = apps.get_model(app_label, model_name)
    if not isinstance(category, CategoryBase):
        category = Category.objects.get(slug=str(category))
    children = category.children.all()
    ids = []
    for cat in list(children) + [category]:
        if hasattr(cat, '%s_set' % set_name):
            ids.extend([x.pk for x in getattr(cat, '%s_set' % set_name).all()[:num]])

    return m.objects.filter(pk__in=ids).order_by('-%s' % date_field)[:num]
dataset/ETHPy150Open callowayproject/django-categories/categories/templatetags/category_tags.py/get_latest_objects_by_category/original