[Python] invalid literal for int() with base 10: 'test'

Discussão em 'Python' iniciado por Stack, Outubro 30, 2024.

  1. Stack

    Stack Membro Participativo

    Basically, this is how it breaks down, I have 3 models (quiz, questions, answers). I have 20 questions, with 4 potential answers (multi-choice), per quiz. The numbers can vary, but you get the point.

    I need to create a form for these items, much like you'd expect in a multiple choice quiz. However, when I create the form by hand in the templates, rather than using django.forms, I get the following:


    invalid literal for int() with base 10: 'test'
    ​

    So I'm trying to mess with the django.forms, but I guess I'm just not grasping the idea of how to build a proper form out of those.

    For what it's worth here are the models:

    class Quiz(models.Model):
    label = models.CharField(blank=True, max_length=400)
    slug = models.SlugField()

    def __unicode__(self):
    return self.label

    class Question(models.Model):
    label = models.CharField(blank=True, max_length=400)
    quiz = models.ForeignKey(Quiz)

    def __unicode__(self):
    return self.label

    class Answer(models.Model):
    label = models.CharField(blank=True, max_length=400)
    question = models.ForeignKey(Question)
    correct = models.BooleanField()

    def __unicode__(self):
    return self.label

    Continue reading...

Compartilhe esta Página