def validate(self, attrs):
    validated = super(UserCreateSerializer, self).validate(attrs)
    if (self.context['created_by'].user_type in READ_ONLY_USER_TYPES):
        if (validated['user_type'] not in READ_ONLY_USER_TYPES):
            raise exceptions.ValidationError({'user_type': ['Read only users can create other read only users only']})
    if ((validated['user_type'] > self.context['created_by'].user_type) and (not self.context['created_by'].is_superuser)):
        raise exceptions.ValidationError({'user_type': ['User cannot create another user with higher permissions']})
    if ((not validated.get('ward')) and (not validated.get('local_body')) and (not validated.get('district')) and (not validated.get('state'))):
        raise exceptions.ValidationError({'__all__': ['One of ward, local body, district or state is required']})
    if (validated.get('user_type') == User.TYPE_VALUE_MAP['BlockAdmin']):
        local_body_object = validated.get('local_body')
        if (local_body_object.block is None):
            raise exceptions.ValidationError({'__all__': ["The local_body doesn't have a Block associated with it"]})
    return validated
def validate(self, attrs):
    validated = super(UserCreateSerializer, self).validate(attrs)
    if (self.context['created_by'].user_type in READ_ONLY_USER_TYPES):
        if (validated['user_type'] not in READ_ONLY_USER_TYPES):
            raise exceptions.ValidationError({'user_type': ['Read only users can create other read only users only']})
    if ((validated['user_type'] > self.context['created_by'].user_type) and (not self.context['created_by'].is_superuser)):
        raise exceptions.ValidationError({'user_type': ['User cannot create another user with higher permissions']})
    if ((not validated.get('ward')) and (not validated.get('local_body')) and (not validated.get('district')) and (not validated.get('state'))):
        raise exceptions.ValidationError({'__all__': ['One of ward, local body, district or state is required']})
    if (validated.get('user_type') == User.TYPE_VALUE_MAP['BlockAdmin']):
        local_body_object = validated.get('local_body')
        if (local_body_object.block is None):
            raise exceptions.ValidationError({'__all__': ["The local_body doesn't have a Block associated with it"]})
    return validated