本文整理汇总了Python中qa.models.Question类的典型用法代码示例。如果您正苦于以下问题:Python Question类的具体用法?Python Question怎么用?Python Question使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Question类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
def save(self):
#question = Question(**self.cleaned_data)
title = self.cleaned_data['title']
text = self.cleaned_data['text']
question = Question(title=title, text=text, author=self._user)
question.save()
return question
示例2: ask
def ask(request):
"""Ask form."""
if request.method == 'POST':
form = AskForm(request.POST)
if form.is_valid():
params = {
'title': form.cleaned_data['title'],
'text': form.cleaned_data['text']
}
if request.user.is_authenticated():
params.update({'author': request.user})
question = Question(**params)
question.save()
return HttpResponseRedirect(
reverse('question', kwargs={'id': question.id})
)
else:
form = AskForm()
context = {'form': form}
return render(request, 'ask.html', context)
示例3: save
def save(self):
if self._user.is_anonymous():
self.cleaned_data['author_id'] = 1
else:
self.cleaned_data['author'] = self._user
ask = Question(**self.cleaned_data)
ask.save()
return ask
示例4: test_model
def test_model(request, *args, **kwargs):
user = User(username='o', password='o')
user.save()
question = Question(title='qwe', text='qwe', author=user)
question.save()
answer = Answer(text='qwe', question=question, author=user)
answer.save()
return HttpResponse('OK', status=200)
示例5: save
def save(self):
#question =Question(**self.cleaned_data)
new_qs = Question(
text=self.cleaned_data['text'],
title=self.cleaned_data['title'],
author=self._user
)
new_qs.save()
return new_qs
示例6: save
def save(self):
data = {
'title': self.cleaned_data['title'],
'text': self.cleaned_data['text'],
'added_at': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
'rating': 0,
'author_id': self._user.id,
}
question = Question(**data)
question.save()
return question
示例7: test_question
def test_question(self):
from qa.models import Question
try:
title = Question._meta.get_field('title')
except FieldDoesNotExist:
assert False, "title field does not exist in Question model"
assert isinstance(title, CharField), "title field is not CharField"
try:
text = Question._meta.get_field('text')
except FieldDoesNotExist:
assert False, "text field does not exist in Question model"
assert isinstance(text, TextField), "text field is not TextField"
try:
added_at = Question._meta.get_field('added_at')
except FieldDoesNotExist:
assert False, "added_at field does not exist in Question model"
assert isinstance(text, DateField) or isinstance(added_at, DateField), "added_at field is not DateTimeField"
try:
rating = Question._meta.get_field('rating')
except FieldDoesNotExist:
assert False, "rating field does not exist in Question model"
assert isinstance(rating, IntegerField), "text field is not IntegerField"
try:
author = Question._meta.get_field('author')
except FieldDoesNotExist:
assert False, "author field does not exist in Question model"
assert isinstance(author, ForeignKey), "author field is not ForeignKey"
assert author.related.parent_model == User, "author field does not refer User model"
try:
likes = Question._meta.get_field('likes')
except FieldDoesNotExist:
assert False, "likes field does not exist in Question model"
assert isinstance(likes, ManyToManyField), "likes field is not ManyToManyField"
assert likes.related.parent_model == User, "likes field does not refer User model"
user, _ = User.objects.get_or_create(username='x', password='y')
try:
question = Question(title='qwe', text='qwe', author=user)
question.save()
except:
assert False, "Failed to create question model, check db connection"
示例8: save
def save(self):
question = Question(**self.cleaned_data)
question.added_at = datetime.now()
question.rating = 0
question.author = self._user
question.save()
return question
示例9: save
def save(self,user):
# self.cleaned_data['author_id'] = 1
post = Question(**self.cleaned_data)
post.author=user
post.save()
return post
示例10: save
def save(self):
question = Question(**self.cleaned_data)
question.save()
return question
示例11: save
def save(self):
self.cleaned_data['author_id'] = 1
askquestion = Question(**self.cleaned_data)
askquestion.save()
return askquestion
示例12: save
def save(self):
question = Question(**self.cleaned_data)
question.author_id = self.user.id
question.save()
return question
示例13: ask_question
def ask_question(request):
if not request.user.is_authenticated():
return redirect('/')
else:
hut_slug = request.POST['hut']
hut = Course.objects.get(slug=hut_slug)
title = request.POST['title']
if len(title) == 0:
return ask(request, error='You need to enter a title.', hut_slug=hut_slug)
content = request.POST['content']
if len(content) == 0:
return ask(request, error='You need to enter some content to your question.', title=title, hut_slug=hut_slug)
tags = request.POST['tags'].strip().replace(',', '').replace('#', '').split(' ')
if len(tags) == 1 and len(tags[0]) == 0:
return ask(request, error='You need to enter some tags.', title=title, content=content, hut_slug=hut_slug)
question = Question(title=title, content=content, author=request.user, course=hut)
question.save()
question.add_tag(hut.slug)
question.add_tag(State.CURRENT_QUARTER)
question.add_follower(request.user)
for tag in tags:
question.add_tag(tag)
if hut.has_approved(request.user):
question.approved = True
question.save()
message_subscribers(hut, question, request.user)
return redirect('/question/%d' % question.id)
return redirect('/?msg=moderation')
示例14: save
def save(self):
question = Question(**self.cleaned_data)
question.author = self._user
question.save()
return question
示例15: save
def save(self):
ask = Question(**self.cleaned_data)
ask.save()
return ask