本文整理汇总了Python中models.Question.author方法的典型用法代码示例。如果您正苦于以下问题:Python Question.author方法的具体用法?Python Question.author怎么用?Python Question.author使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Question
的用法示例。
在下文中一共展示了Question.author方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_user
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import author [as 别名]
def test_get_user():
user = User()
user.username = u"test"
user.set_password("test123")
assert user.save()
assert user._id
q = Question()
q.question = u"test"
q.author = u"anon"
q.user = user.username
assert q.save(validate=True)
assert q._id
user_from_question = q.get_user()
assert user_from_question._id == user._id
q.user = u"anon!"
q.save()
assert not q.get_user()
示例2: test_get_unanswered_questions
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import author [as 别名]
def test_get_unanswered_questions():
user = User()
user.username = u"test"
user.set_password("test123")
assert user.save()
assert user._id
q = Question()
q.question = u"test"
q.author = u"anon"
q.user = user.username
assert q.save(validate=True)
assert q._id
user_from_db = User.one({'username': 'test'})
assert user_from_db.unanswered_questions().count() == 1
示例3: save
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import author [as 别名]
def save(self):
question = Question(**self.cleaned_data)
question.author = self._user
question.save()
return question