Created
April 8, 2013 17:15
-
-
Save ageron/5338551 to your computer and use it in GitHub Desktop.
This file contains 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
>>> from mongoengine import * | |
>>> class FacebookUser(Document): | |
... meta = { "allow_inheritance": False } | |
... facebook_id = StringField(primary_key = True, max_length = 20) | |
... name = StringField() | |
... def __unicode__(self): | |
... return u"/".join((self.facebook_id, self.name or u"")) | |
... | |
>>> connect("test") | |
Connection('localhost', 27017) | |
>>> FacebookUser.objects.delete() | |
>>> FacebookUser.objects | |
[] | |
>>> FacebookUser.objects.get_or_create(facebook_id = "1234") | |
(<FacebookUser: 1234/>, True) | |
>>> FacebookUser.objects | |
[] | |
>>> FacebookUser.objects.get_or_create(facebook_id = "1234", name = "John Smith") | |
(<FacebookUser: 1234/John Smith>, True) | |
>>> FacebookUser.objects | |
[<FacebookUser: 1234/John Smith>] | |
>>> FacebookUser.objects.get_or_create(facebook_id = "5678", name = "David Peters") | |
(<FacebookUser: 5678/David Peters>, True) | |
>>> FacebookUser.objects | |
[<FacebookUser: 1234/John Smith>, <FacebookUser: 5678/David Peters>] | |
>>> FacebookUser.objects.get_or_create(facebook_id = "1234", name = "Bjarne Stroustrup") | |
(<FacebookUser: 1234/Bjarne Stroustrup>, True) | |
>>> FacebookUser.objects | |
[<FacebookUser: 5678/David Peters>, <FacebookUser: 1234/Bjarne Stroustrup>] |
When I add extra attributes, such as the name (line 18), then the object is properly saved.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 15 says that the object was created when it fact it wasn't (as line 17 shows). Isn't that a bug?