For a simple ModelSerializer, the response JSON contains instances of 
models, which fails when the response is JSON serialized. For example:

class AccountSerializer(ModelSerializer):
    tokens = SerializerMethodField()

    def get_tokens(self, obj):
        token_list = []
        for token in obj.get_tokens():
            token_list.append({
                'client'     : token.client,   # <----- token.client is an 
instance of a model
                'account_id' : token.account_id
            })
        return token_list

The response fails with the following error:
TypeError: <client object> is not JSON serializable

This was perfectly valid in rest framework 2.x, as the result of the 
get_tokens method would then be automatically serialized further.

I'm wondering, is there an easy way to upgrade for this type of expected 
behavior to DRF v3, or can I simply not rely on code like this and 
explicitly serialize objects? As an aside, I've noticed instances of models 
in the result of ModelSerializer calls where the ModelSerializer was 
serializing anything more than depth=1.

After extensive searching, I have not found another issue like this one and 
so any help would be appreciated.
Thank you

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to