开发者

django - get the id of just updated record

On my Django app I'm doing an update like this:

r = Mycords.objects.select_related().filter(name=r_name).update(title=开发者_Python百科r_title, message_body=r_message)

I need to get the id of just updated record so I can use it somewhere else on the code. Any ideas?


Whoah.

Firstly, if this is just a single record, you should use get rather than filter.

Secondly, what's select_related doing in there?

Thirdly, all the updated records are in r. So you can access their IDs from there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜