Filter results Serializer Django

0

Good, I have a problem because I want to filter the data of an FK in a serializer.

class ProductoArmarioSerializer(serializers.ModelSerializer):
    imagenes = FotoSerializer(many=True)
    tallas = StockSerializer(many=True)

    class Meta:
        model = Producto
        fields = ['id', 'nombre', 'color', 'estado_prod', 'descrip', 'medidas', 'p_compra', 'categoria',
                     'p_venta', 'estado_rev', 'marca', 'imagenes','escaparate','tallas']


class MiArmarioSerializer(serializers.ModelSerializer):
    productos = ProductoArmarioSerializer(many=True)
    usuario = UserSerializer()
    seguidores = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
    likes = serializers.PrimaryKeyRelatedField(many=True, read_only=True)

    class Meta:
        model = Perfil
        fields = ['id','usuario','boutique','tel','entrg_pais','entrg_dep',
                    'entrg_ciudad','entrg_direccion','entrg_cp','rmt_pais','rmt_dep',
                    'rmt_direccion','rmt_ciudad','rmt_cp','num_cc','avatar','descp_armario',
                    'tipo_ident','cedula','nit','tarjeta','alt_tarjeta','propietario_cc',
                    'banco','tipo_cc','follow','seguidores','productos','likes']

I want the products that you return to be those that have status_rev = 4 and the rest discard them

    
asked by F Delgado 28.12.2017 в 09:27
source

1 answer

1

Try doing it from views.py an example can be:

class PruebaViewSet(viewsets.ModelViewSet):
    queryset=Producto.objects.filter(estado_rev=4)
    serializer_class = ProductoArmarioSerializer
    
answered by 02.01.2018 / 10:49
source