Pierre-Sassoulas / django-survey

A django survey app that can export results as CSV or PDF using your native language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The random feature

rickabiz opened this issue · comments

When I set question options to content it works fine but if I set the option as random or none it shows the error bellow in browser.

Cannot resolve keyword 'random' into field. Choices are: content, correct, id, question, question_id

Hello, could you be more specific, where are you setting the option ?

Thanks for replay... In mcq app admin

Your code

models.py

ANSWER_ORDER_OPTIONS = (
('content', 'Content'),
# NOT WORKING('none', 'None'),
#NOT WORKING('random', 'Random'),
)

class MCQQuestion(Question):

answer_order = models.CharField(
    max_length=30, null=True, blank=True,
    choices=ANSWER_ORDER_OPTIONS,
    help_text="A ordem na qual escolha múltipla \
                 opções de resposta são exibidas \
                 para o usuário",
    verbose_name="Ordem de resposta")

def check_if_correct(self, guess):
    answer = Answer.objects.get(id=guess)

    if answer.correct is True:
        return True
    else:
        return False

def order_answers(self, queryset):
    if self.answer_order == 'content':
        return queryset.order_by('content')
    """
    NOT WORKING

    if self.answer_order == 'random':
        return queryset.order_by('random')
    if self.answer_order == 'none':
        return queryset.order_by('None')
    """
def get_answers(self):
    return self.order_answers(Answer.objects.filter(question=self))

def get_answers_list(self):
    return [(answer.id, answer.content) for answer in self.order_answers(Answer.objects.filter(question=self))]

def answer_choice_to_string(self, guess):
    return Answer.objects.get(id=guess).content


class Meta:
    verbose_name = "Questionário"
    verbose_name_plural = "Questionários"

class Answer(models.Model):
question = models.ForeignKey(MCQQuestion, verbose_name='Question', on_delete=models.CASCADE)

content = models.CharField(max_length=1000,
                           blank=False,
                           help_text="Digite o texto de resposta que \
                                         você quer exibir",
                           verbose_name="Conteúdo")

correct = models.BooleanField(blank=False,
                              default=False,
                              help_text="Esta é a resposta correta?",
                              verbose_name="Correta")


def __str__(self):
    return self.content


class Meta:
    verbose_name = "Pergunta"
    verbose_name_plural = "Perguntas"

Thank you so much for replay

Ricardo - SP/Brazil

Sorry I don't think I understand the question, it seems it's about code unrelated to the survey app itself, it seems the code come from a modifed survey app called "mcq" ?

upssss my mistake... This question was related to another app, my sincerely apologizes and thank you in have answered to me.

My question to you is if there is a way to the generate an output table of answers at the end only if the user has this privilege on a group of users eg, administrators.

Best regards and I'm sorry my mistake again! :-)

No problem :)

Right now it's possible to download a PDF report generated with LaTeX summarizing the survey with pie diagram (this is configurable in the admin).