Skip to content

Instantly share code, notes, and snippets.

@vanatteveldt
Created October 25, 2013 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanatteveldt/7162984 to your computer and use it in GitHub Desktop.
Save vanatteveldt/7162984 to your computer and use it in GitHub Desktop.
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