简体   繁体   English

在 Django 中查询数据库

[英]Query database in Django

My first problem is I want to get the inserted latest id in auth_user on Django but currently it showing the name of the row database.我的第一个问题是我想在 Django 的 auth_user 中获取插入的最新 id,但目前它显示的是行数据库的名称。 I use the example below.我使用下面的例子。 The result should be Id value not the name.结果应该是 Id 值而不是名称。 Please help me请帮我

 obj = User.objects.latest('id')

The second problem is I want to insert in auth_user_user_permission table like this.第二个问题是我想像这样插入 auth_user_user_permission 表。 The problem is how to convert this into django format.问题是如何将其转换为 django 格式。

lastestid = User.objects.latest('id')
insert into auth_user_user_permission where user_id=latestid and permission_id =(Select auth_permission Where name="sample" )
obj = User.objects.all().order_by('-id')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM