本文整理汇总了Python中qa.models.Question类的典型用法代码示例。如果您正苦于以下问题:Python Question类的具体用法?Python Question怎么用?Python Question使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Question类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:codeonline,项目名称:Stepic-WebTech,代码行数:7,代码来源:forms.py
示例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)
开发者ID:greenleafs,项目名称:webtech,代码行数:25,代码来源:views.py
示例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
开发者ID:evgeny495,项目名称:stepic_project,代码行数:8,代码来源:forms.py
示例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)
开发者ID:igorlutsenko,项目名称:stepic_9,代码行数:8,代码来源:views.py
示例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
开发者ID:mike1994s,项目名称:web,代码行数:9,代码来源:forms.py
示例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
开发者ID:itsanti,项目名称:stepic_webtech,代码行数:11,代码来源:forms.py
示例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"
开发者ID:mialinx,项目名称:tp-stepic-tasks,代码行数:40,代码来源:server_l11.py
示例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
开发者ID:Woolfno,项目名称:web_project,代码行数:7,代码来源:forms.py
示例9: save
def save(self,user):
# self.cleaned_data['author_id'] = 1
post = Question(**self.cleaned_data)
post.author=user
post.save()
return post
开发者ID:Megaco,项目名称:web,代码行数:6,代码来源:forms.py
示例10: save
def save(self):
question = Question(**self.cleaned_data)
question.save()
return question
开发者ID:leonvsg,项目名称:swp,代码行数:4,代码来源:forms.py
示例11: save
def save(self):
self.cleaned_data['author_id'] = 1
askquestion = Question(**self.cleaned_data)
askquestion.save()
return askquestion
开发者ID:StealthyFox,项目名称:web,代码行数:5,代码来源:forms.py
示例12: save
def save(self):
question = Question(**self.cleaned_data)
question.author_id = self.user.id
question.save()
return question
开发者ID:namax,项目名称:stepic_web_project,代码行数:5,代码来源:forms.py
示例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')
开发者ID:imclab,项目名称:QuestionHut,代码行数:41,代码来源:views.py
示例14: save
def save(self):
question = Question(**self.cleaned_data)
question.author = self._user
question.save()
return question
开发者ID:arzahs,项目名称:Course-web-technology,代码行数:5,代码来源:forms.py
示例15: save
def save(self):
ask = Question(**self.cleaned_data)
ask.save()
return ask
开发者ID:domitori2013,项目名称:stepic,代码行数:4,代码来源:forms.py
示例16:
["sixth","what is the time now??", datetime.now(),17,56,User.objects.get(username="max")],
["seventh","how much is the fish",datetime.now(),12,8,User.objects.get(username="luchnck")],
["eghth","WTF 0_o ???", datetime.now(),6,14,User.objects.get(username="max")],
["ninegth","what is the time now??", datetime.now(),10,20,User.objects.get(username="max")],
["tenth","how much is the fish",datetime.now(),0,0,User.objects.get(username="luchnck")],
["eleven","WTF 0_o ???", datetime.now(),14,56,User.objects.get(username="max")],
["tvelve","what is the time now??", datetime.now(),22,34,User.objects.get(username="max")],
["forteen","how much is the fish",datetime.now(),24,56,User.objects.get(username="luchnck")],
["sixteenth","WTF 0_o ???", datetime.now(),23,32,User.objects.get(username="max")],
["eigtheenth","what is the time now??", datetime.now(),34,17,User.objects.get(username="max")],
]
for question in questions:
title,text,added_at,rating,likes,author = question
question=Question(title=title,text=text,added_at=added_at,rating=rating,likes=likes,author=author)
question.save()
answers = [
["dorogo",datetime.now(),Question.objects.get(title="first"),User.objects.get(username="max")],
["togo!togo",datetime.now(),Question.objects.get(title="second"),User.objects.get(username="luchnck")],
["13:00 o clock!!", datetime.now(),Question.objects.get(title="second"),User.objects.get(username="luchnck")],
]
for answer in answers:
text,added_at,question,author = answer
answer=Answer(text=text,added_at=added_at,question=question,author=author)
answer.save()
开发者ID:luchnck,项目名称:teststep,代码行数:28,代码来源:initDB.py
示例17: save
def save(self, user):
q = Question(author=user, **self.cleaned_data)
q.save()
return q
开发者ID:avzabr,项目名称:stepic-web-tech,代码行数:4,代码来源:forms.py
示例18: save
def save(self):
user, _ = User.objects.get_or_create(username='x', defaults={'password': 'y'})
q = Question(title=self.cleaned_data['title'], text=self.cleaned_data['text'], author=user)
q.save()
return q
开发者ID:tolstovdmit,项目名称:stepic-django,代码行数:6,代码来源:forms.py
示例19: save
def save(self):
self.cleaned_data['author'] = self.user
question = Question(**self.cleaned_data)
question.save()
#question = Question.objects.create(text=self.cleaned_data['text'], title=self.cleaned_data['title'], author=self.user)
return question
开发者ID:MelroiN,项目名称:web_test,代码行数:6,代码来源:forms.py
示例20: save
def save(self):
self.cleaned_data['author'] = self.user
question = Question(**self.cleaned_data)
question.save()
return question
开发者ID:meanmail,项目名称:stepic_web_technology,代码行数:5,代码来源:forms.py
注:本文中的qa.models.Question类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论