Django Database design -- Is this a good stragety for overriding defaults
- by rh0dium
Hi SO's
I have a question on good database design practices and I would like to leverage you guys for pointers. The project started out simple.
Hey we have a bunch of questions we want answered for every project (no problem)
Which turned into...
Hey we have so many questions can we group them into sections (yup we can do that)
Which lead into..
Can we weight these questions and I don't really want some of these questions for my project (Yes but we are getting difficult)
And then I'm thinking they will want to have each section have it's own weight..
Requirements
So there's the requirements - For n number of project
Allow a admin member the ability select the questions for a project
Allow the admin member to re-weigh or use the default weights for the questions
Allow the admin member to re-weight the sections
Allow team members to answer the questions.
So here is what I came up with. Please feel free to comment and provide better examples
models.py
from django.db import models
from django.contrib.sites.models import Site
from django.conf import settings
class Section(models.Model):
"""
This describes the various sections for a checklist:
"""
name = models.CharField(max_length=64)
description = models.TextField()
class Question(models.Model):
"""
This simply provides a simple way to list out the questions.
"""
question = models.CharField(max_length=255)
answer_type = models.CharField(max_length=16)
description = models.TextField()
section = models.ForeignKey(Section)
class ProjectQuestion(models.Model):
"""
These are the questions relevant to the project
"""
question = models.ForeignKey(Question)
answer = models.CharField(max_length=255)
required = models.BooleanField(default=True)
weight = models.FloatField(default = XXX)
class Project(models.Model):
"""
Here is where we want to gather our questions
"""
questions = models.ManyToManyField(ProjectQuestion)
Immediate questions:
- When I start a project - any ideas on how to "pre-populate" the questions (and ultimately the weights) for the project?
- Is there a generally accepted method for doing this process that I am missing? Basically the idea that you refer to the questions overide your own default weight, and store the answer?
- It appears that a good chuck of the work will be done in the views and that a lot of checking will need to occur there? Is that OK?
Again - feel free to give me better strategies!!
Thanks