django中怎样调用sql数据库中的存储过程?存储过程返回一个表,可以用模型类查询吗?

django中怎样调用sql数据库中的存储过程?存储过程返回一个表,可以用模型类查询吗?

问题描述:

如题,django中怎样调用sql数据库中的存储过程?存储过程返回一个表,可以用模型类查询吗?

自己榜定下模型,代码类似
http://blog.sina.com.cn/s/blog_70dc706b0100oavh.html
mysql也是类似的

  • 数据库配置在settings中,DATABASE
  • django数据库ORM,使用django models
  • 创建django models 在Meta类中,加入有一张test表
class TestModel(models.Model):
                class Meta:
                                db_table = 'test'  # 指明数据库表名
  • 下面就可以通过创建TestModel对象,操作test数据库
  • test = TestModel()
  • test.object.get(id=1) # 查询单条数据
  • test.name = ‘张三’
  • test.save() # 数据修改
  • test.object.filter("") # 查询集
  • test.object.create() # 新建数据
  • test.object.delete() # 删除数据