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


Python Question.author方法代码示例

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


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

示例1: ask

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import author [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

示例2: handle

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import author [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

示例3: doimport

# 需要导入模块: from questions.models import Question [as 别名]
# 或者: from questions.models.Question import author [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


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