'Returns a query for a limited and offset list of both types of contents,
filtered and in some order.'

def _union_of_contents_query(self, container, filters=None, limit=None, offset=None, order_by=None, **kwargs):

    order_by = (order_by if (order_by is not None) else self.default_order_by)
    order_by = (order_by if isinstance(order_by, (tuple, list)) else (order_by,))
    contained_query = self._contents_common_query_for_contained(container.id)
    subcontainer_query = self._contents_common_query_for_subcontainer(container.id)
    contents_query = contained_query.union(subcontainer_query)
    for orm_filter in (filters or []):
        contents_query = contents_query.filter(orm_filter)
    contents_query = contents_query.order_by(*order_by)
    if (limit is not None):
        contents_query = contents_query.limit(limit)
    if (offset is not None):
        contents_query = contents_query.offset(offset)
    return contents_query
