本文整理汇总了Python中models.Message.add方法的典型用法代码示例。如果您正苦于以下问题:Python Message.add方法的具体用法?Python Message.add怎么用?Python Message.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Message
的用法示例。
在下文中一共展示了Message.add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import add [as 别名]
def post(self):
request_dict = request.get_json()
if not request_dict:
response = {'message': 'No input data provided'}
return response, status.HTTP_400_BAD_REQUEST
errors = message_schema.validate(request_dict)
if errors:
return errors, status.HTTP_400_BAD_REQUEST
message_message = request_dict['message']
if not Message.is_unique(id=0, message=message_message):
response = {'error': 'A message with the same message already exists'}
return response, status.HTTP_400_BAD_REQUEST
try:
category_name = request_dict['category']['name']
category = Category.query.filter_by(name=category_name).first()
if category is None:
# Create a new Category
category = Category(name=category_name)
db.session.add(category)
# Now that we are sure we have a category
# create a new Message
message = Message(
message=message_message,
duration=request_dict['duration'],
category=category)
message.add(message)
query = Message.query.get(message.id)
result = message_schema.dump(query).data
return result, status.HTTP_201_CREATED
except SQLAlchemyError as e:
db.session.rollback()
resp = {"error": str(e)}
return resp, status.HTTP_400_BAD_REQUEST
示例2: pyforum_message_view
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import add [as 别名]
def pyforum_message_view(self):
id_topic = self.request.matchdict['id_topic']
topic_title = self.request.matchdict['topic_title']
topics = Message.objects().filter(topic__icontains=id_topic)
form = Form(self.request,schema=MessageSchema())
if form.validate():
context = {'name' : form.data['name'],
'description': form.data['description'],
'topic': id_topic}
Message.add(context)
return HTTPFound(location='/message_list/{0}/{1}'.format(id_topic,topic_title))
return {'title': 'List View PyForum',
'topics':topics,
'id_topic':id_topic,
'topic_title':topic_title,
'form' : FormRenderer(form)
}