Exemplo n.º 1
0
    def containers_in_use(self, request, *args, **kwargs):
        """
        Returns a list of Containers that are associated with Distilleries.
        This filters out any Containers that are unused.
        """
        filtered_queryset = Container.objects.filter(distillery__isnull=False)
        parents = filtered_queryset.distinct()

        serializer = ContainerSerializer(parents,
                                         many=True,
                                         context={'request': request})
        return Response(serializer.data)
Exemplo n.º 2
0
 def _get_data_by_name(self, request):
     """
     Takes a REST API request with an optional names argument consisting of
     a comma-separated list of Container names. Returns the serialized data
     for the specified Containers or the data for all Containers if no names
     were given.
     """
     queryset = Container.objects.all().order_by('name')
     names = self.request.query_params.get('names', None)
     filtered_queryset = self._filter_by_names(queryset, names)
     serializer = ContainerSerializer(filtered_queryset,
                                      many=True,
                                      context={'request': request})
     return serializer.data
Exemplo n.º 3
0
class DistilleryDetailSerializer(serializers.ModelSerializer):
    """Serializer for a |Distillery| object."""

    id = serializers.ReadOnlyField(source='pk')  # pylint: disable=C0103
    container = ContainerSerializer()
    contexts = ContextSerializer(many=True)

    class Meta(object):
        """Metadata options."""

        model = Distillery
        depth = 2
        fields = (
            'collection',
            'container',
            'contexts',
            'id',
            'name',
            'url',
        )