首页 > 数据库技术 > 详细

ORM数据库的增删改查

时间:2018-04-30 10:02:55      阅读:297      评论:0      收藏:0      [点我收藏+]

数据库可视化工具:

https://sqlitestudio.pl/index.rvt

from app01 import models
def orm(request):
    #增加数据
    # 方法1:
    # models.UserInfo.objects.create(username=‘root‘,password=‘root123‘)
    # 方法2:
    # obj = models.UserInfo(username=‘zte‘,password=‘zte‘)
    # obj.save()
    # 方法三:
    # dict1={‘username‘:‘zte1‘,"password":‘zte1‘ }
    # obj = models.UserInfo(**dict1)
    # obj.save()
    #查找数据
    # result=models.UserInfo.objects.all()
    # # print result
    # for row in result:
    #     print row.id,row.username,row.password
    # result = models.UserInfo.objects.filter(username=‘root‘)
    # result = models.UserInfo.objects.filter(username=‘root‘,password=‘root123‘)
    # for row in result:
    #     print row.id,row.username,row.password
    #删除
    # models.UserInfo.objects.filter(id=‘4‘).delete()
    #更新
    models.UserInfo.objects.all().update(password=45678)
    return HttpResponse(‘adasd‘)

  

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models

# Create your models here.
class UserInfo(models.Model):
    username=models.CharField(max_length=32)
    password=models.CharField(max_length=64)

class zte(models.Model):
    id=models.AutoField(primary_key=True)  #主键,自增
    username=models.CharField(max_length=32)
    password=models.CharField(max_length=64)
    email=models.CharField(max_length=64,null=True)

  

ORM数据库的增删改查

原文:https://www.cnblogs.com/qiangayz/p/8972673.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!