开发者

django - get the id of just updated record

开发者 https://www.devze.com 2023-03-20 15:49 出处:网络
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)

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

精彩评论

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