python(Django 创建数据,增删改查)

from app01 import models
def orm(request):
    #创建增加数据A
    # models.UserInfo.objects.create(
    #     username='root',
    #     password='123'
    # )
    # return HttpResponse('orm')

    ###创建增加数据AA
    dic = {'username':'eric','password':'666'}
    models.UserInfo.objects.create(**dic)
    # return HttpResponse('orm')


    # # 创建增加数据B
    # obj = models.UserInfo(username='root',password='123')
    # obj.save()
    # return HttpResponse('orm')

from app01 import models
def orm(request):
    # 创建
    # models.UserInfo.objects.create(username='root',password='123')

    # dic = {'username': 'eric', 'password': '666'}
    # models.UserInfo.objects.create(**dic)

    # obj = models.UserInfo(username='alex',password='123')
    # obj.save()

    # 查
    # result = models.UserInfo.objects.all()
    # result = models.UserInfo.objects.filter(username='root',password='123')
    #
    # result,QuerySet => Django => []
    # [obj(id,username,password),obj(id,username,password), obj(id,username,password)]
    # for row in result:
    #     print(row.id,row.username,row.password)
    # print(result)

    # 删除
    # models.UserInfo.objects.filter(username="alex").delete()

    # 更新
    # models.UserInfo.objects.filter(id=3).update(password="69")

    return HttpResponse('orm')

发表评论