def METHOD_NAME(queryset, as_field="tasks_attr"):
    """Attach tasks as json column to each object of the queryset.
    :param queryset: A Django user stories queryset object.
    :param as_field: Attach tasks as an attribute with this name.
    :return: Queryset object with the additional `as_field` field.
    """
    model = queryset.model
    sql = """SELECT json_agg(row_to_json(t))
                FROM(
                    SELECT
                        tasks_task.id,
                        tasks_task.ref,
                        tasks_task.subject,
                        tasks_task.status_id,
                        tasks_task.is_blocked,
                        tasks_task.is_iocaine,
                        projects_taskstatus.is_closed
                FROM tasks_task
                INNER JOIN projects_taskstatus on projects_taskstatus.id = tasks_task.status_id
                WHERE user_story_id = {tbl}.id
                ORDER BY tasks_task.us_order, tasks_task.ref
                ) t
                """
    sql = sql.format(tbl=model._meta.db_table)
    queryset = queryset.extra(select={as_field: sql})
    return queryset