当前位置: 首页>>代码示例>>Python>>正文


Python Question.save方法代码示例

本文整理汇总了Python中questions.models.Question.save方法的典型用法代码示例。如果您正苦于以下问题:Python Question.save方法的具体用法?Python Question.save怎么用?Python Question.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在questions.models.Question的用法示例。


在下文中一共展示了Question.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import save [as 别名]
    def handle(self, *args, **options):

        Question.objects.all().delete()
        Answer.objects.all().delete()
        print('Deleted existing data')

        answers = []
        with open(settings.BASE_DIR + '/../' + self.csv_file, 'r') as csvfile:
            reader = csv.reader(csvfile, delimiter='|')
            next(reader, None)

            for row in reader:

                if(len(answers) > 80):
                    save_answers(answers)
                    answers = []


                q = Question(question=row[0])
                q.save()

                print('Saved question with id ' + str(q.id));

                answers.append(Answer(question=q, choice=row[1], correct=True))

                for i in row[2].split(','):
                    answers.append(Answer(question=q, choice=i, correct=False))

        save_answers(answers)
开发者ID:agronick,项目名称:WebServiceExample,代码行数:31,代码来源:populate_db.py

示例2: ask

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import save [as 别名]
def ask(request):
    ask_form = AskQuestion(request.POST or None)
    args = {}
    args['form'] = ask_form
    if request.POST and ask_form.is_valid():
        question = Question(text=ask_form.cleaned_data['text'], title=ask_form.cleaned_data['title'])
        tags = ask_form.cleaned_data['tags']

        g = Tag.objects.all()
        getTag = tags.split(', ')

        for tag in getTag:
            counter = 0
            for l in g:
                if l.tag == tag:
                    counter += 1
            if counter == 0:
                t = Tag(tag=tag)
                t.save()


        user = auth.get_user(request)
        question.author = user

        question.save()
        a = g.filter(tag__in=getTag)
        question.tags.add(*a)
        return redirect('questionGet', question_id=question.id)

    else:
        return render(request, 'ask.html', args)
开发者ID:Zanexess,项目名称:AskingHeapProject,代码行数:33,代码来源:views.py

示例3: doimport

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import save [as 别名]
    def doimport(self,data):

        from django.contrib.auth.models import User
        from questions.models import Question, Answer
        from tagging.models import Tag
    
        try:
            question = Question()
            question.content = data['question']
            question.tags = data['tags']
            question.author = User.objects.get(pk=0) #FIXME: System smrtr user: use constant?
            question.save() # Save to allow m2m

            # Create correct answer
            c = Answer()
            c.content = data['correct']
            c.is_correct = True
            c.question = question
            c.save()
            
            # Save incorrect answers
            data['incorrect'] = filter(lambda x: len(x)>0, data['incorrect']) # Remove empty items
            for incorrect in data['incorrect']:
                ic = Answer()
                ic.content = incorrect
                ic.is_correct = False
                ic.question = question
                ic.save()
        except:
            print "Error importing:" + data['question']    
开发者ID:mfitzp,项目名称:smrtr,代码行数:32,代码来源:import_questions.py

示例4: test_percent

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import save [as 别名]
    def test_percent(self, switch_is_active):
        """Test user API with all defaults."""
        switch_is_active.return_value = True
        u = user()
        u.save()
        add_permission(u, Profile, 'view_kpi_dashboard')
        question = Question(title='Test Question',
                            content='Lorem Ipsum Dolor',
                            creator_id=u.id)
        question.save()
        answer = Answer(question=question, creator_id=u.id,
                        content="Test Answer")
        answer.save()

        question.solution = answer
        question.save()

        url = reverse('api_dispatch_list',
                      kwargs={'resource_name': 'kpi_solution',
                              'api_name': 'v1'})
        self.client.login(username=u.username, password='testpass')
        response = self.client.get(url + '?format=json')
        eq_(200, response.status_code)
        r = json.loads(response.content)
        eq_(r['objects'][0]['with_solutions'], 1)
        eq_(r['objects'][0]['without_solutions'], 0)
开发者ID:erikrose,项目名称:kitsune,代码行数:28,代码来源:test_api.py

示例5: gradeQuestion

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import save [as 别名]
def gradeQuestion(request):
	questionList = json.loads(request.POST['questions'])
	for question in questionList:
		sentenceText = question['sentence']
		questionText = question['question']
		labelText = question['label']
		gradeVal = question['grade']
		if Sentence.objects.filter(text=sentenceText).exists() :
			sentence = Sentence.objects.get(text=sentenceText)
		else:
			sentence = Sentence(text=sentenceText)
			sentence.save()

		if Question.objects.filter(text=questionText).exists():
			question = Question.objects.get(text=questionText)
		else:
			question = Question(text=questionText)
			question.save()

		if Label.objects.filter(text=labelText).exists():
			label = Label.objects.get(text = labelText)
		else:
			label = Label(text = labelText)
			label.save()
		grade = Grade(sentence=sentence,question=question,label=label,grade=gradeVal)
		grade.save()
	return HttpResponse('200')
开发者ID:mickeyinfoshan,项目名称:django-swuquestion,代码行数:29,代码来源:views.py

示例6: handle

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import save [as 别名]
    def handle(self, *args, **options):
        users = list(User.objects.all())

        for i in range(10):
            t = Topic()
            t.name = u'Topic Name {}'.format(i)
            t.description = u'Topic Description {}'.format(i)
            t.save()
        topics = list(Topic.objects.all())

        for j in range(100):
            q = Question()
            q.author = random.choice(users)
            q.title = u'title {}'.format(j)
            q.text = u'text {}'.format(j)
            q.pub_date = datetime.datetime.now()
            q.is_published = True
            q.save()
            q.topics = random.sample(topics, random.randint(1, 6))
        questions = list(Question.objects.all())

        for k in range(100):
            c = Comment()
            c.author = random.choice(users)
            c.question = random.choice(questions)
            c.text = u'text {}'.format(k)
            c.pub_date = datetime.datetime.now()
            c.save()
开发者ID:PhilSk,项目名称:src,代码行数:30,代码来源:data_filling.py

示例7: test_notification_created

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import save [as 别名]
    def test_notification_created(self):
        """Creating a new question auto-watches it."""

        u = User.objects.get(pk=118533)
        q = Question(creator=u, title='foo', content='bar')
        q.save()

        assert check_watch(Question, q.id, u.email, 'reply')
开发者ID:chowse,项目名称:kitsune,代码行数:10,代码来源:test_models.py

示例8: test_notification_created

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import save [as 别名]
    def test_notification_created(self):
        """Creating a new question auto-watches it for answers."""

        u = User.objects.get(pk=118533)
        q = Question(creator=u, title='foo', content='bar')
        q.save()

        assert QuestionReplyEvent.is_notifying(u, q)
开发者ID:Akamad007,项目名称:kitsune,代码行数:10,代码来源:test_models.py

示例9: setUp

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import save [as 别名]
    def setUp(self):
        super(TestQuestionMetadata, self).setUp()

        # add a new Question to test with
        question = Question(title='Test Question',
                            content='Lorem Ipsum Dolor',
                            creator_id=1)
        question.save()
        self.question = question
开发者ID:Akamad007,项目名称:kitsune,代码行数:11,代码来源:test_models.py

示例10: test_no_inactive_users

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import save [as 别名]
 def test_no_inactive_users(self):
     """Ensure that inactive users' questions don't appear in the feed."""
     u = User.objects.get(pk=118533)
     u.is_active = False
     u.save()
     q = Question(title='Test Question', content='Lorem Ipsum Dolor',
                  creator_id=118533)
     q.save()
     assert q.id not in [x.id for x in QuestionsFeed().items()]
开发者ID:Akamad007,项目名称:kitsune,代码行数:11,代码来源:test_feeds.py

示例11: create_question

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import save [as 别名]
 def create_question(self, name):
     user = UserWithAvatar.objects.order_by("?")[:1][0]
     pub_date = timezone.now()
     title = "Could you help me with " + name + "?"
     text = self.lorem * 10
     tags = Tag.objects.order_by("?")[:5]
     question = Question(author=user, pub_date=pub_date, text=text, title=title)
     question.save()
     for tag in tags:
         question.tags.add(tag)
     question.save()
开发者ID:Oktosha,项目名称:askPupkin,代码行数:13,代码来源:filldata.py

示例12: create

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import save [as 别名]
    def create(self, validated_data):
        """
        Custom create method. Prepare and create nested choices.

        """
        choices_data = validated_data.pop("choices", None)

        question = Question(**validated_data)
        question.save()

        self.create_choices(question, choices_data)

        return question
开发者ID:ballotify,项目名称:django-backend,代码行数:15,代码来源:serializers.py

示例13: test_delete_question_removes_flag

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import save [as 别名]
    def test_delete_question_removes_flag(self):
        """Deleting a question also removes the flags on that question."""
        question = Question(title='Test Question',
                            content='Lorem Ipsum Dolor',
                            creator_id=118533)
        question.save()
        FlaggedObject.objects.create(
            status=0, content_object=question,
            reason='language', creator_id=118533)
        eq_(1, FlaggedObject.objects.count())

        question.delete()
        eq_(0, FlaggedObject.objects.count())
开发者ID:Akamad007,项目名称:kitsune,代码行数:15,代码来源:test_models.py

示例14: ask

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import save [as 别名]
def ask(request):
    ask_form = AskQuestion(request.POST or None)
    args = {}
    args['form'] = ask_form
    if request.POST and ask_form.is_valid():
        question = Question(text_question=ask_form.cleaned_data['text'], title=ask_form.cleaned_data['title'])

        user = auth.get_user(request)
        question.user = user

        question.save()
        return render(request, 'question.html', args)
    else:
        return render(request, 'question.html', args)
开发者ID:virtuosmipt,项目名称:StackOverFlow_Web,代码行数:16,代码来源:views.py

示例15: test_vote_on_question

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import save [as 别名]
	def test_vote_on_question(self):
		"""
		Test that a hitting a URL will incrememt a question's vote count
		"""
		question_1 = Question(text="How can my team get started with testing?",
							  votes=3,
							  created=datetime.datetime.utcnow().replace(tzinfo=utc),
							  status="new")
		question_1.save()
		
		response = self.client.get('/vote/1/up/')
		self.assertRedirects(response, '/')
		
		question_1_after_vote = Question.objects.get(id=1)
		self.assertEqual(question_1_after_vote.votes, 4)
开发者ID:kevinharvey,项目名称:test-driven-django-development,代码行数:17,代码来源:test_unit.py


注:本文中的questions.models.Question.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。