当前位置: 首页>>代码示例>>Python>>正文


Python Message.add方法代码示例

本文整理汇总了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
开发者ID:xianjunzhengbackup,项目名称:code,代码行数:35,代码来源:views.py

示例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)
            }
开发者ID:tgonzales,项目名称:pyramid-forum,代码行数:20,代码来源:views.py


注:本文中的models.Message.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。