def attach_issue_custom_attributes(queryset, as_field='issue_custom_attributes_attr'):
 model = queryset.model
 sql = '\n             SELECT json_agg(\n                        row_to_json(custom_attributes_issuecustomattribute)\n                        ORDER BY custom_attributes_issuecustomattribute.order\n                    )\n               FROM custom_attributes_issuecustomattribute\n              WHERE custom_attributes_issuecustomattribute.project_id = {tbl}.id\n          '
 sql = sql.format(tbl=model._meta.db_table)
 queryset = queryset.extra(select={as_field: sql})
 return queryset

def attach_issue_custom_attributes ( queryset , as_field = 'issue_custom_attributes_attr' ) : model = queryset . model sql = '\n             SELECT json_agg(\n                        row_to_json(custom_attributes_issuecustomattribute)\n                        ORDER BY custom_attributes_issuecustomattribute.order\n                    )\n               FROM custom_attributes_issuecustomattribute\n              WHERE custom_attributes_issuecustomattribute.project_id = {tbl}.id\n          ' sql = sql . format ( tbl = model . _meta . db_table ) queryset = queryset . extra ( select = { as_field : sql } ) return queryset
attach a json issue custom attributes representation to each object of the queryset .