django 模型操作

 

# 添加
Fruit.objects.create(name='Apple')
# 更新
UserProfile.objects.filter(user=admin).update(**{'online':False,'channel':''})

# 保存或者更新   defaults 用来更新/保存  user=admin用来查询
UserProfile.objects.update_or_create(defaults={'user':admin,
                                                          'online':True,
                                                          'channel':self.channel_name
                                                          },user=admin)
# 查询
# 单查询
User.objects.get(id=self.admin_id)
# 全部和多查询
Membership.objects.all()
UserProfile.objects.filter(user=admin)
#删除
Line.objects.filter(admin_id=self.admin_id).delete()

 

posted @ 2019-03-13 10:21  MvloveYouForever  阅读(99)  评论(0编辑  收藏  举报