I have a Serializer but I want to set a calculation whether to include it in serialized return objects or not.
class TradeSerializer(serializers.ModelSerializer):
.
.
.
.
def to_representation(self, instance):
ret = super().to_representation(instance)
if ret['countdown'] < 5:
# STOP! Do not return an object anymore!
return
return ret
But the syntax above will return something like ret[None]. I looking for an absolute exclusion