I'm trying to do something pretty simple, but I'm new to Django. I have a quiz system set up for an experiment I'm running.
The relevant entries in models.py follow:
class Flavor(models.Model):
name = models.CharField(max_length=100)
def __unicode__(self):
return self.name
class Passage(models.Model):
name = models.CharField(max_length=100)
def __unicode__(self):
return self.name
class PassageText(models.Model):
passage = models.ForeignKey(Passage)
flavor = models.ForeignKey(Flavor)
contents = models.TextField()
def __unicode__(self):
return "[%s#%s]" % (self.passage, self.flavor)
class Question(models.Model):
passage = models.ForeignKey(Passage)
text = models.TextField()
def __unicode__(self):
return "[%s#%s]" % (self.passage, self.text)
class AnswerOption(models.Model):
question = models.ForeignKey(Question)
text = models.TextField()
is_correct = models.BooleanField(default=False)
def __unicode__(self):
return "[%s#%s]" % (self.question, self.text)
class TestSubject(models.Model):
GENDER_CHOICES = ( ('M','Male'), ('F','Female'), )
EDUCATION_CHOICES = ( ('SH', 'Some high school'), ('HS', 'High school diploma'), ('SC', 'Some college'), ('CD', 'College degree'), ('MD', 'Master\'s degree'), ('PH','PhD or higher education'), )
GPA_CHOICES = ( ('1', '1.0-1.5'), ('2', '1.5-2.0'), ('3', '2.0-2.5'), ('4', '2.5-3.0'), ('5', '3.0-3.5'), ('6', '3.5-4.0'), ('7', '4.0-4.5'), ('8', '4.5-5.0'), )
ip = models.CharField(max_length=30)
completed = models.BooleanField(default=False)
created_time = models.DateTimeField(default=datetime.now)
time_used = models.IntegerField(default=0, help_text='number of seconds used for test')
age = models.PositiveIntegerField()
gender = models.CharField(max_length=2, choices=GENDER_CHOICES)
education = models.CharField(max_length=2, choices=EDUCATION_CHOICES)
school = models.CharField(max_length=200)
grad_year = models.PositiveIntegerField()
gpa = models.CharField(max_length=2, choices=GPA_CHOICES)
sat_verbal = models.PositiveIntegerField(blank=True)
sat_math = models.PositiveIntegerField(blank=True)
sat_writing = models.PositiveIntegerField(blank=True)
sat_overall = models.PositiveIntegerField(blank=True)
english_is_your_first_language = models.BooleanField()
kerberos_name_if_applying_for_900_credit = models.CharField(max_length=200, blank=True)
def __unicode__(self):
return "[%s#%s]" % (self.ip, self.created_time)
class TestSequence(models.Model):
subject = models.ForeignKey(TestSubject)
order = models.IntegerField(help_text='1..n')
pt = models.ForeignKey(PassageText)
time_used = models.IntegerField(default=0, help_text='number of seconds used for test')
def __unicode__(self):
return "[%s#%d]" % (self.subject, self.order)
class QuestionSequence(models.Model):
tseq = models.ForeignKey(TestSequence)
order = models.IntegerField(help_text='0..n')
question = models.ForeignKey(Question)
selectedanswer = models.ForeignKey(AnswerOption, blank=True, null=True, default=None)
def __unicode__(self):
return "[%s#%d]" % (self.tseq, self.order)
I want to essentially have a page that just gives me a table of all TestSubject objects (and all their properties) as well as a list of which passages they did and a count of how many questions they got right in that passage.