Created
October 25, 2013 22:48
-
-
Save vanatteveldt/7162984 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
class Article(AmcatModel): | |
[...] | |
def save_and_index(self, articleset=None): | |
""" | |
Save this article to the database and index, adding it to the given articleset | |
""" | |
if self.pk: | |
raise Exception("Cannot only call save_and_index on unstored articles!") | |
self.save() | |
if articleset: | |
articleset.add_articles([self], add_to_index=False) | |
amcates.ES().add_articles(self) | |
@classmethod | |
def create(cls, articleset=None, **attributes): | |
""" | |
Create and return an article with the given attributes and adds | |
it to the given set and indexes it. | |
""" | |
s = Article(**attributes) | |
s.save_and_index(articleset=articleset) | |
return s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment