@@ -268,20 +268,7 @@ def _is_dynamic(self):
268268        )
269269
270270    def  get_attribute (self , instance ):
271-         serializer  =  self .serializer 
272-         model  =  serializer .get_model ()
273- 
274-         # attempt to optimize by reading the related ID directly 
275-         # from the current instance rather than from the related object 
276-         if  not  self .kwargs ['many' ] and  serializer .id_only ():
277-             return  instance 
278-         elif  model  is  not None :
279-             try :
280-                 return  getattr (instance , self .source )
281-             except  model .DoesNotExist :
282-                 return  None 
283-         else :
284-             return  instance 
271+         return  instance 
285272
286273    def  to_representation (self , instance ):
287274        """Represent the relationship, either as an ID or object.""" 
@@ -296,18 +283,18 @@ def to_representation(self, instance):
296283            # try the faster way first: 
297284            if  hasattr (instance , source_id ):
298285                return  getattr (instance , source_id )
299-             elif  model  is  not None :
300-                 # this is probably a one-to-one field, or a reverse related 
301-                 # lookup, so let's look it up the slow way and let the 
302-                 # serializer handle the id dereferencing 
303-                 try :
304-                     instance  =  getattr (instance , source )
305-                 except  model .DoesNotExist :
306-                     instance  =  None 
307286
308287        # dereference ephemeral objects 
309288        if  model  is  None :
310289            instance  =  getattr (instance , source )
290+         else :
291+             # this is probably a one-to-one field, or a reverse related 
292+             # lookup, so let's look it up the slow way and let the 
293+             # serializer handle the id dereferencing 
294+             try :
295+                 instance  =  getattr (instance , source )
296+             except  model .DoesNotExist :
297+                 instance  =  None 
311298
312299        if  instance  is  None :
313300            return  None 
0 commit comments