Hi
How to filter get_queryset() QueryResultset records based on Non-model computed fields.
I tried using the below code in the serializer.py, but the get_queryset returns “” for the records that does not have computed list, instead of removing it from the QueryResultset,
Any idea what needs to be done to get this rectified and skip these records from the serializer easily?
class MyListSerializer(serializers.ModelSerializer):
computed_my_list=serializers.SerializerMethodField()
class Meta:
model = models.MyList
fields = (
‘id’,
‘computed_my_list’
)
read_only = [‘id’,‘computed_my_list’]
def to_representation(self, instance):
data = super(MyListSerializer, self).to_representation(instance)
if not data.get('computed_my_list'):
return ''
return data
def get_computed_my_list(self,obj):
myList=event.my_list.get_computed_date_list(obj,cond_var1,cond_var2)
if myList:
return myList
====
Kindly let me know your view.