def PermissionMod(field, permissions):
 class Modded(field, ):
  @classmethod
  def many_init(cls, *args, **kwargs):
   kwargs['child'] = field()
   return PermissionMod(serializers.ListSerializer, permissions)(*args, **kwargs)
  def get_attribute(self, instance):
   if self.check_permissions(instance):
    return super(Modded, self).get_attribute(instance)
   else:
    raise fields.SkipField()
  def check_permissions(self, obj):
   request = self.context.get('request')
   for Perm in permissions:
    perm = Perm()
    if (not perm.has_permission(request, self)):
     return False
    if (not perm.has_object_permission(request, self, obj)):
     return False
   return True
 return Modded

def PermissionMod ( field , permissions ) : class Modded ( field , ) : @ classmethod def many_init ( cls , * args , ** kwargs ) : kwargs [ 'child' ] = field ( ) return PermissionMod ( serializers . ListSerializer , permissions ) ( * args , ** kwargs ) def get_attribute ( self , instance ) : if self . check_permissions ( instance ) : return super ( Modded , self ) . get_attribute ( instance ) else : raise fields . SkipField ( ) def check_permissions ( self , obj ) : request = self . context . get ( 'request' ) for Perm in permissions : perm = Perm ( ) if ( not perm . has_permission ( request , self ) ) : return False if ( not perm . has_object_permission ( request , self , obj ) ) : return False return True return Modded
takes a class and modifies it to conditionally hide based on permissions .