+1 on this, Bruno explained it better than my first email.

On Mon, Jun 27, 2011 at 7:22 PM, bruno desthuilliers <
bruno.desthuilli...@gmail.com> wrote:

> On Jun 27, 12:30 pm, Coulson Thabo Kgathi <zeeco...@gmail.com> wrote:
> > ok
> >
> > #models.py file
> >
> > from django.db import models
> > from django.forms import ModelForm
> > from django import forms
> > from choices import YESNO, AGE, OPTIONS1, OPTIONS2, OPTIONS3, OPTIONS4,
> > OPTIONS5, OPTIONS6, OPTIONS7, OPTIONS8, OPTIONS9, OPTIONS10, OPTIONS11,
> > OPTIONS14, OPTIONS15, OPTIONS16, OPTIONS17, OPTIONS18, OPTIONS19
> >
> > class Questxs(models.Model):
> >
> >     quest1 = models.CharField(
> >         verbose_name = '1. Have you ever had sexual intercourse?',
> >         blank = False,
> >         choices = YESNO,
> >         max_length = 5,
> >     )
> >
> >     quest2 = models.CharField(
> >         verbose_name = '2. At what age did you begin sexual
> intercuorse?',
> >         blank = False,
> >         choices = AGE,
> >         max_length = 5,
> >         null = True,
> >     )
> >
> >     quest3 =models.CharField(
> >         verbose_name = '3. When was the last time you had sexual
> > intercourse?',
> >         blank = False,
> >         choices = OPTIONS1,
> >         max_length = 25,
> >         null=True
> >     )
> (snip)
>
> OMG :(
>
> Ok, you firts have to learn what a *relational* database is all
> about.  The poll tutorial migh be a good starting point : a "poll" is
> a question with a set of possible answers, and your "questionnaire" is
> a set of questions with each a set of possible answers (do you notice
> some pattern here ?)
>
> You model should look something  like this:
>
> class Questionnaire(models.Model):
>    title = models.CharField(verbose_name="Title", max_length=50)
>    description = models.TextField(verbose_name="Description",
> blank=True, default="")
>    date_created = models.DateTimeField(auto_now_add=True)
>
> class Question(models.Model):
>    questionnaire = models.ForeignKey(Questionnaire)
>    question = models.CharField(verbose_name="Question",
> max_length="255")
>    help = models.TextField(verbose_name="Help", blank=True,
> default="")
>
> class Choice(models.Model):
>    question = models.ForeignKey(Question)
>    text = model.CharField(verbose_name="Text", max_length="255")
>
> class Answer(models.Model):
>    user = models.ForeignKey(User) # or IP address or any other
> session identifier
>    choice = models.ForeignKey(Question)
>
>
> Notice how I didn't hard-code anything. All questionnaires /
> questions / choices / answers are stored in the database, which means
> you can create has many different questionnaires as you want without
> having to write a single line of code.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to