I am writing an app for a simple survey.
For possible answers I need "Yes/Now", "1 out of 1 to 5", and a short text
In the admin it should be selectable, what kind of answer should be given.
My models:
from django.db import models
from django.contrib.contenttypes.models import ContentType
CHOICES=((1,'excactly true'),(2,'mostly true'),(3,'mostly untrue'),(4,'untrue'),(5,'I don\'t know '))
class Answer(models.Model):
question = models.ForeignKey("Question")
class ChoiceAnswer(Answer):
answer = models.IntegerField(max_length=1, choices=CHOICES)
def __unicode__(self):
return u'%s: %s'%(self.question, self.answer)
class TextAnswer(Answer):
answer= models.CharField(max_length=255)
def __unicode__(self):
return u'%s: %s'%(self.question, self.answer)
class BooleanAnswer(Answer):
answer= models.BooleanField(choices=((True,'yes'),(False,'no')))
def __unicode__(self):
return u'%s: %s'%(self.question, self.answer)
class Question(models.Model):
question = models.CharField(max_length=255)
answer_type = models.ForeignKey(ContentType)
def __unicode__(self):
return u'%s'%self.question
Is there a (hopefully: simple) way for generating the form by looping over all questions and creating the an answer form compatible to the question's answer_type?
And is it possible to filter contenttypes for answer_type = models.ForeignKey(ContentType)
so that only the answertypes will be shown?