Hi. Ok, i'm shit at describing. Here's a relationship diag.
In Django i've made my models like:
from django.db import models
from datetime import datetime
class Survey(models.Model):
name = models.CharField(max_length=100)
pub_date = models.DateTimeField('date published',default=datetime.now)
def __unicode__(self):
return self.name
# This model should be abstracted by a more specific model
class Section(models.Model):
survey = models.ForeignKey(Survey)
name = models.CharField(max_length=100)
def __unicode__(self):
return self.name
# Models for supporting the 'ratings' mode
class RatingSection(Section):
pass
class RatingQuestion(models.Model):
section = models.ForeignKey(RatingSection)
name = models.CharField(max_length=255)
def __unicode__(self):
return self.name
class RatingAnswer(models.Model):
section = models.ForeignKey(RatingSection)
name = models.CharField(max_length=60)
def __unicode__(self):
return self.name
class RatingVotes(models.Model):
question = models.ForeignKey(RatingQuestion)
answer = models.ForeignKey(RatingAnswer)
votes = models.PositiveIntegerField(default=0)
def __unicode__(self):
return self.votes + self.answer.name + ' votes for ' + self.question.name
# Models for supporting the 'multichoice' mode
class MultiChoiceSection(Section):
can_select_multiple = models.BooleanField()
class MultiChoiceQuestion(models.Model):
section = models.ForeignKey(MultiChoiceSection)
name = models.CharField(max_length=255)
def __unicode__(self):
return self.name
class MultiChoiceAnswer(models.Model):
section = models.ForeignKey(MultiChoiceSection)
name = models.CharField(max_length=60)
votes = models.PositiveIntegerField(default=0)
def __unicode__(self):
return self.name
The problem is that I'm almost certain that's not the right way to do it, and even if it is, I can't work out how to allow the admin area in Django to display a selection to the user asking what sub-type of section they want.
What would be the best way to structure models of this sort?