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.
精彩评论