Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. obj = MyModel.objects.create(val=1)
  2. MyModel.objects.filter(pk=obj.pk).update(val=F('val') + 1)
  3. # At this point obj.val is still 1, but the value in the database
  4. # was updated to 2. The object's updated value needs to be reloaded
  5. # from the database.
  6.  
  7. # approach 1)
  8. obj = MyModel.objects.get(pk=obj.pk)
  9.  
  10. # approach 2)
  11. obj.refresh_from_db()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement