views:

38

answers:

2

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:

  1. When I start a project - any ideas on how to "pre-populate" thequestions (and ultimately the weights) for the project? This is not how to load the questions. For that we have json. I want to know how to "copy" the template questions to the project?
  2. 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?
  3. 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

A: 
  1. Django - Providing Initial Data
  2. Not sure what you are asking here
  3. I would say that it's ok to have that logic in the view as it pertains to how the data is presented, not necessarily how it is processed, or validated.
Jason Miesionczek
A: 

This is what I would have as far as tables:

Questions table (this would include the default weight for the question) Project table (defines the details of the project) ProjectQuestions (has projectid and questionid and new weight value (originally populated with the default wireght but the admin can change it.)

Of course you can do something simliar with the sections as well. You need the linking table because you don't want a change to the default weight to change already completed projects and becasue you want the weight to be changeable by project.

As to how to do that using django, beats me, as I would never design a database using an ORM.

HLGEM
Agreed!! That is my question - how do you do this linking using an ORM.!! Super
rh0dium