Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. ##
  2. ## Can somebody explain why this is happening
  3. ## and/or a workaround for this craziness?
  4. ##
  5.  
  6. ## iPython Shell 1
  7. from django.contrib.auth.models import User
  8.  
  9. ## iPython Shell 2
  10. from django.contrib.auth.models import User
  11.  
  12. ## iPython Shell 1
  13. a = User()
  14. a.username = 'foo'
  15. a.email = 'foo@localhost.com'
  16. a.save()
  17. print a.id  #1
  18.  
  19. ## iPython Shell 2
  20. print User.objects.get(pk=1).id  #1
  21.  
  22. ## iPython Shell 1
  23. b = User()
  24. b.username = 'bar'
  25. b.email = 'foo@localhost.com'
  26. b.save()
  27. print b.id  #2
  28.  
  29. ## iPython Shell 2
  30. print User.objects.get(pk=2)  #Raises User.DoesNotExist
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement