return super(cls, Question).get(question_id=question_id) def answer(self, user, text): answer = Answer.create(user, self, text) return answer def get_answers(self, offset_answer=None, limit=None): answers = Answer.objects(question_id=self.question_id) return answers @property def id(self): return self.question_id Question.vote = vote(QuestionRating) class QuestionByCategory(Model): # sorted by newest first category_id = UUID(primary_key=True, partition_key=True) # day = DateTime(primary_key=True, partition_key=True) question_id = TimeUUID(primary_key=True, clustering_order="DESC") user_id = Text() text = Text(required=True) class QuestionByCategorySorted(Model): """ using day to limit the tombstone effect for paginating way back """
from uuid import uuid1 from cassandra.cqlengine.models import Model from cassandra.cqlengine.columns import * from killranswers.ratings.models import AnswerRating, vote class Answer(Model): question_id = TimeUUID(primary_key=True) answer_id = TimeUUID(primary_key=True, default=uuid1) user_id = Text() text = Text() @classmethod def create(cls, user, question, text): answer = super(cls, Answer).create(question_id=question.question_id, user_id=user.user_id, text=text) return answer @property def id(self): return self.answer_id Answer.vote = vote(AnswerRating)