<s> from rest_framework import serializers <EOL> from rest_framework . reverse import reverse <EOL> def get_obj_property_value ( obj , field ) : <EOL> """<STR_LIT>""" <EOL> _attr_list = field . split ( '<STR_LIT:.>' ) <EOL> if len ( _attr_list ) > <NUM_LIT:1> : <EOL> tmp_obj = getattr ( obj , _attr_list [ <NUM_LIT:0> ] ) <EOL> return get_obj_property_value ( tmp_obj , '<STR_LIT:.>' . join ( _attr_list [ <NUM_LIT:1> : ] ) ) <EOL> return getattr ( obj , field ) <EOL> class HyperlinkedMultiRelatedField ( serializers . HyperlinkedRelatedField ) : <EOL> lookup_fields = ( ( '<STR_LIT>' , '<STR_LIT>' ) , ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> lookup_fields = kwargs . pop ( '<STR_LIT>' , None ) <EOL> self . lookup_fields = lookup_fields or self . lookup_fields <EOL> super ( HyperlinkedMultiRelatedField , self ) . __init__ ( * args , ** kwargs ) <EOL> def get_url ( self , obj , view_name , request , format ) : <EOL> kwargs = { } <EOL> for slug , field in self . lookup_fields : <EOL> lookup_field = get_obj_property_value ( obj , field ) <EOL> kwargs [ slug ] = lookup_field <EOL> return reverse ( <EOL> view_name , kwargs = kwargs , request = request , format = format ) </s>
