1、添加数据

    Department.objects.create(title="销售部")
    Department.objects.create(title="IT部")
    Department.objects.create(title="运营部")

2、删除数据

2.1删除所有数据
    UserInfo.objects.all().delete()
2.2删除过滤后的数据
    Department.objects.filter(id=2).delete()

3、获取数据

    #获取到的数据是QuerySet类型
    data_list = UserInfo.objects.all()
    for obj in data_list:
        print(obj.id,obj.name,obj.password,obj.age)
    #获取第一条数据(对象)
    row_obj = UserInfo.objects.filter(id=6).first()
    print(row_obj.name,row_obj.password)

4、更新数据

    UserInfo.objects.all().update(password=9999)
    #筛选并更新数据
    UserInfo.objects.filter(id=6).update(password=45678)

5、添加数据

    if request.method == "GET":
        return render(request, "info_add.html")
    user = request.POST.get("user")
    pwd = request.POST.get("password")
    age = request.POST.get("age")

    UserInfo.objects.create(name=user,password=pwd,age=age)

VIRIYA
1 声望0 粉丝