django 操作mysql

来源:互联网 发布:地图软件开发 编辑:程序博客网 时间:2024/06/08 22:31

1、增:

models.GameRoom.objects.create(owner=userName, gameStatus=False)

2、查(有两种,get查不到会报错,filter是拿到一个字典集合):

gameListObject = models.GamerList.objects.get(name=userName)gameListObject = models.GamerList.objects.filter(name=userName)                if  gameListObject.count() == 1:                    return HttpResponse(json.dumps(response_data), content_type="application/json")                else :                    models.GamerList.objects.create(name=userName, status='live', turns=False, owner=False)                    return HttpResponse(json.dumps(response_data), content_type="application/json")

3、改:

models.GameRoom.objects.filter(owner=userName).update(status=True, count=9, rand=rand)

4、删:

models.User.objects.filter(name='monkey').delete()


0 0
原创粉丝点击