<s> from rest_framework import routers , serializers , viewsets <EOL> from . models import Group , Permission , User <EOL> class UserSerializer ( serializers . ModelSerializer ) : <EOL> class Meta : <EOL> model = User <EOL> fields = ( '<STR_LIT:id>' , '<STR_LIT:name>' ) <EOL> class GroupSerializer ( serializers . ModelSerializer ) : <EOL> class Meta : <EOL> model = Group <EOL> fields = ( '<STR_LIT:id>' , '<STR_LIT:name>' ) <EOL> class PermissionSerializer ( serializers . ModelSerializer ) : <EOL> class Meta : <EOL> model = Permission <EOL> fields = ( '<STR_LIT:id>' , '<STR_LIT:name>' ) <EOL> class UserWithGroupsSerializer ( serializers . ModelSerializer ) : <EOL> class Meta : <EOL> model = User <EOL> fields = ( '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> groups = GroupSerializer ( many = True ) <EOL> class GroupWithPermissionsSerializer ( serializers . ModelSerializer ) : <EOL> class Meta : <EOL> model = Group <EOL> fields = ( '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> permissions = PermissionSerializer ( many = True ) <EOL> class UserWithAllSerializer ( serializers . ModelSerializer ) : <EOL> class Meta : <EOL> model = User <EOL> fields = ( '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT>' ) <EOL> groups = GroupWithPermissionsSerializer ( many = True ) <EOL> class UserViewSet ( viewsets . ModelViewSet ) : <EOL> queryset = User . objects . all ( ) <EOL> serializer_class = UserSerializer <EOL> class UserWithGroupsViewSet ( viewsets . ModelViewSet ) : <EOL> queryset = User . objects . all ( ) <EOL> serializer_class = UserWithGroupsSerializer <EOL> class UserWithAllViewSet ( viewsets . ModelViewSet ) : <EOL> queryset = User . objects . all ( ) <EOL> serializer_class = UserWithAllSerializer <EOL> router = routers . DefaultRouter ( ) <EOL> router . register ( r'<STR_LIT>' , UserWithGroupsViewSet ) <EOL> router . register ( r'<STR_LIT>' , UserWithGroupsViewSet ) <EOL> router . register ( r'<STR_LIT>' , UserWithAllViewSet ) </s>
