I am designing a quiz engine by using django.
In the models.py, I have such classes:
class Quiz (models.Model):
quiz_id = models.AutoField (primary_key=True)
problem_desc = models.TextField (blank=True)
problem_has_resource = models.BoolField ()
problem_is_choice = models.BooleanField ()
def __unicode__ (self):
return self.quiz_id
class Choice (models.Model):
choice_id = models.AutoField (primary_key=True)
quiz_id = models.ForeignKey (Quiz);
choice_desc = models.CharField (max_length = 500)
is_answer = models.BooleanField ()
class Answer (models.Model):
quiz_id = models.ForeignKey (Quiz)
input_answer = models.FloatField ()
class Quiz_Resource (models.Model):
quiz_id = models.ForeignKey (Quiz)
title = form.CharField (max_length = 50)
file = forms.FileField ()
def __unicode__ (self):
return self.file.name
A quiz may need to be inputted an “Answer” or chosen a choice. A quiz may have many choices. A quiz may have some extra resource. I want the boolfield to control the admin page style, set formal info. How can I achieve it?
Bow, thanks!
enter code here
First of all, you have to relate your quiz model to your Choice, Answer and Quiz_Ressource models.
That way you tell Django that your Quiz model references to multiple models of the type Choice, Answer and Quiz_Ressource. You can search for the concept of ManyToMany in relational databases if this is unclear.
After you have rewritten your model like that, there will be fields for adding and selecting choices, anwers and ressources on the admin pages.
To continue along with django use the documentation as provided here: https://docs.djangoproject.com/en/1.3/topics/db/models/#many-to-many-relationships
Your needs for custom admin templates is a different story. You can do that with something like this in your apps admin.py:
I don’t know exactly what you want to do with your custom admin view, so i skipped that part. But that should be the path to follow.