<s> from rest_framework import serializers <EOL> from rest_framework_transforms . exceptions import TransformBaseNotDeclaredException <EOL> from rest_framework_transforms . utils import get_transform_classes <EOL> class BaseVersioningSerializer ( serializers . ModelSerializer ) : <EOL> """<STR_LIT>""" <EOL> transform_base = None <EOL> def to_representation ( self , instance ) : <EOL> """<STR_LIT>""" <EOL> if not self . transform_base : <EOL> raise TransformBaseNotDeclaredException ( "<STR_LIT>" ) <EOL> data = super ( BaseVersioningSerializer , self ) . to_representation ( instance ) <EOL> if instance : <EOL> request = self . context . get ( '<STR_LIT>' ) <EOL> if request and hasattr ( request , '<STR_LIT:version>' ) : <EOL> for transform in get_transform_classes ( self . transform_base , base_version = request . version , reverse = True ) : <EOL> data = transform ( ) . backwards ( data , request , instance ) <EOL> return data </s>
