Thanks for such a prompt response.

I am catching a custom exception here.

I don't think filtering the queryset will solve the problem since the
exception is raised after performing some operation on properties of
object. I will explore if it can be done through validation.
Thanks again! 😄

On Thu, 2 Jul, 2020, 1:43 AM DIPENDRA BHATT, <dipenbhat...@gmail.com> wrote:

> Serializermethodfield is a read only field used to append some custom data
> to the serialization of objects. If you wanna skip this object in case a
> exception occurs to fetch the custom field, this probably was a
> validation/filtering issue on the quesryset part which is being supplied to
> the serializer class to serialize the queryset. It's better if you do the
> validation/filtering part of the queryset before hand(checkout django
> filters, awesome library) and then when your query set has only those
> objects which you want serialize them.
>
>
> On Thu, Jul 2, 2020, 1:23 AM Brent O'Connor <epicse...@gmail.com> wrote:
>
>> What exception is it throwing?
>>
>> On Wednesday, July 1, 2020 at 2:49:46 PM UTC-5, Gagan Deep wrote:
>>>
>>> I have a SerializerMethodField in serializer. I am catching an exception
>>> in the function like below. I want to skip this object in the ListView
>>> entirely if that exception is caught. How can I do this?
>>>
>>> I am using ListApiView from rest_framework.generics
>>>
>>>
>>> classFooSerializer(serializers.ModelSerializer):
>>>     foo = serializers.SerializerMethodField()
>>>
>>>     get_foo(self, object):
>>>     try:
>>>         # Do something here
>>>     except:
>>>     # If an exception is captured than skip this object
>>>
>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django REST framework" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-rest-framework+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-rest-framework/c15a63b8-b052-4ade-ae0f-c53e57d4a848o%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-rest-framework/c15a63b8-b052-4ade-ae0f-c53e57d4a848o%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-rest-framework+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-rest-framework/CAEiaXZk171ADiBUiuwXPqz-uewDEOug%2BB52U-xvAXdTUhg-uUw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-rest-framework/CAEiaXZk171ADiBUiuwXPqz-uewDEOug%2BB52U-xvAXdTUhg-uUw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/CAOX69xrP3QPTMnEJLW1RAwoDUQcjN7jN%2BmZVPkrc-vtX0WiAmA%40mail.gmail.com.

Reply via email to