def post(self): """ Create a new instance of the given resource """ DBSession = sqla_session() # Make sure the caller is authorized to create self.request.context.check_authorization(self.request, self.request.context.resource.get_api_config('create', 'auth')) # OK, create the resource resource = self.request.context.resource.create(self.request.POST, self, self.request, self.request.context.defaults) DBSession.add(resource) DBSession.flush() primary_key_name = resource.primary_key_name() primary_key_value = getattr(resource, primary_key_name) return ResourceCreated(primary_key_value)
def build_unique_query(cls, key, value): return sqla_session().query(cls).filter(getattr(cls, key)==value)