def list(request): queryset = Body.objects.all() queryset = sort_by_field(queryset, 'followers', reverse=True, filt=Q(followers__active=True)) serializer = BodySerializerMin(queryset, many=True) return Response(serializer.data)
def get_children(obj): """Gets a min serialized children of a Body.""" children = obj.children.prefetch_related('child') children = sort_by_field(children, 'child__followers', reverse=True, filt=Q(child__followers__active=True)) return [BodySerializerMin(x.child).data for x in children.all()]
def get_parents(obj): """Gets a min serialized parents of a Body.""" parents = obj.parents.prefetch_related('parent') parents = sort_by_field(parents, 'parent__followers', reverse=True, filt=Q(parent__followers__active=True)) return [BodySerializerMin(x.parent).data for x in parents.all()]
def get_children(obj): """Gets a min serialized children of a Body.""" children = sort_by_field(obj.children.all(), 'child__followers', reverse=True) return [BodySerializerMin(x.child).data for x in children]
def get_parents(obj): """Gets a min serialized parents of a Body.""" parents = sort_by_field(obj.parents.all(), 'parent__followers', reverse=True) return [BodySerializerMin(x.parent).data for x in parents]
def list(cls, request): #pylint: disable=unused-argument queryset = Body.objects.all() queryset = sort_by_field(queryset, 'followers', reverse=True) serializer = BodySerializerMin(queryset, many=True) return Response(serializer.data)