Created
April 12, 2013 15:15
-
-
Save theeluwin/5372769 to your computer and use it in GitHub Desktop.
race condition problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Info(models.Model): | |
| itemCount = models.PositiveIntegerField(default = 0) | |
| class Item(models.Model): | |
| name = models.CharField(max_length = 40) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def foo(info, name): | |
| try: item = Item.objects.get(name = name) | |
| except: | |
| item = Item(name = name) | |
| item.save() | |
| info.itemCount += 1 | |
| info.save() | |
| return item |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
실제 상황에선 get_or_create를 사용 할 수 없는 상황입니다.