Created
September 26, 2013 12:30
-
-
Save namlook/6713491 to your computer and use it in GitHub Desktop.
MongoKit simple inheritance example 3
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 mongokit import ObjectId, Connection | |
connection = Connection() | |
@connection.register | |
class UserNugget(Core): | |
__collection__ = "user_nuggets" | |
structure = { | |
"url": unicode, | |
"topics": [unicode], | |
"user_id": unicode | |
} | |
required_fields = ["url", "topics", "user_id"] | |
def save(self, *args, **kwargs): | |
super(self, UserNugget).save(*args, **kwargs) | |
nugget = self.db.Nugget.find_one({"url": self.url}) | |
if not nugget: | |
nugget = self.db.Nugget(url=url, discoverer=self.user_id) | |
nugget.save() | |
self.db.Nugget.collection.update({"url": self.url}, {"$addToSet": {"topics": {"$each": self.topics}}, "$inc": 1}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment