Also if a Question changes and it is used in multiple quizzes all question 
instances will also need to change.

I think I am missing something. Here is my models.py


class Product(models.Model):
    name = models.CharField(max_length=256, unique=True)

    def __unicode__(self):
        return self.name
class Topic(models.Model):
    name = models.CharField(max_length=256)
    product = models.ForeignKey('Product', related_name='topics')

    class Meta:
        unique_together = ("name", "product")

    def __unicode__(self):
        return self.name
class Module(models.Model):
    name = models.CharField(max_length=256, unique=True)
    threshold = models.IntegerField()
    topic = models.ForeignKey('Topic', related_name='modules')

    def __unicode__(self):
        return self.name
class Choice(models.Model):
    question = models.ForeignKey('Question', related_name='choices')
    choice = models.CharField(max_length=255)
    order = models.IntegerField(default=0)
    count = models.IntegerField(default=0, editable=False)
    is_correct = models.BooleanField(default=False)

    def __unicode__(self):
        return self.choice
#multiple choice questionclass Question(models.Model):
    quiz = models.ForeignKey('Quiz', related_name='questions')
    question = models.CharField(max_length=64)
    
    module = models.ForeignKey('Module', related_name='questions')

    times_correct = models.IntegerField(editable=False, default=0)
    times_total = models.IntegerField(editable=False, default=0)

    def _get_average(self):
        "Returns the average in percent"
        if self.times_total != 0:
            return (self.times_correct / float(self.times_total))*100
        return 0.0
    average = property(_get_average)

    def __unicode__(self):
        return self.question
class Quiz(models.Model):
    #id = models.UUIDField(primary_key=True)
    name = models.CharField(max_length=64)
    #questions = models.ManyToManyField(Question)
    created_by = models.ForeignKey(settings.AUTH_USER_MODEL, 
related_name="quizzes")

    #questions = models.ManyToManyField(QuestionManager, null=True, 
related_name="quiz")

    class Meta:
        verbose_name_plural = "quizzes"

    def __unicode__(self):
        return self.name


On Wednesday, 10 April 2013 16:30:20 UTC-4, Cody Scott wrote:
>
> I also want to have the same question in multiple quizzes. But the count 
> for each option should be dependent on the Quiz. I can do the same thing to 
> Quiz in the admin and add Questions Inline but then to add Choices to the 
> Questions I need to go to the question panel and there will be a lot of 
> duplicate questions and it will hard to tell which question is for which 
> quiz.
>
> I'm not even adding the Choices to the admin because there will be so many 
> duplicates, but I can't not add Question to the admin because I still need 
> to set choices.
>
> Is there a way to Inline 2 steps? So that I can set Choices for a Question 
> when I am making a Quiz?
>
> On Wednesday, 10 April 2013 13:38:14 UTC-4, Cody Scott wrote:
>>
>> I am trying to store questions in a database.
>> I don't to set a fixed number of options for the question, some questions 
>> could have 4 or 2 or 5.
>>
>> Currently I am using a ManyToManyField to a table that just contains a 
>> CharField.
>> This works but creating an option requires making another Choice object 
>> and selecting that, also when you want to select a Choice that has already 
>> been created you have to use that little box in the admin and it doesn't 
>> scale when you have hundreds of options.
>>
>> Even if I wanted to have 4 options every time what is the recommended way 
>> without having four CharFields?
>>
>> class Choice(models.Model):
>>     choice = models.CharField(max_length=255)
>>     def __unicode__(self):
>>         return self.choice
>>  #multiple choice questionclass Question(models.Model):
>>     question = models.CharField(max_length=64)
>>     answer = models.CharField(max_length=255)
>>     choices = models.ManyToManyField(Choice, related_name='questions', 
>> verbose_name='options')
>>     module = models.ForeignKey('Module', related_name='questions')
>>  
>>     times_correct = models.IntegerField(editable=False, default=0)
>>     times_total = models.IntegerField(editable=False, default=0)
>>  
>>     def _get_average(self):
>>         "Returns the average in percent"
>>         if self.times_total != 0:
>>             return (self.times_correct / float(self.times_total))*100
>>         return 0.0
>>     average = property(_get_average)
>>  
>>     def __unicode__(self):
>>         return self.question
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to