Hello Djangonauts,
I am creating a new application to support the creation of online poll
(survey). The goals for this application is to support both:
-a> The creation of the survey performed by the technical writers
-b> Store the answers given by the interviewees
The first aspect is similar to what is demonstrated in the tutorial so
it was relatively easy to come up with a proposal. The part that I
find difficult is to represent the second one.
It would be great if someone could suggest a (the best) way to store
the answers given by each interviewee. So far I am using a "class"
called answer but I am not sure that this is the right thing to do.
Thank you for your help.
Here it is the models I am having so far:
=======models.py=========
from django.db import models
import datetime
class Survey(models.Model):
name = models.CharField(maxlength=20)
description= models.CharField(maxlength=200)
start_date=models.DateField("Effective from")
end_date=models.DateField("Effective to")
def __str__(self):
return self.name
def is_effective(self):
if start_date<datetime.date.today()<end_date:
return True
else:
return False
class Admin:
search_fields = ('name','description')
list_display = ('name', 'start_date','end_date')
list_filter = ['name', 'start_date','end_date']
class Poll(models.Model):
survey=models.ForeignKey(Survey,edit_inline=models.TABULAR)
title=models.CharField(maxlength=20,core=True)
question = models.CharField(maxlength=200)
pub_date = models.DateField('date published',auto_now=True)
def __str__(self):
return self.title
def was_published_today(self):
return self.pub_date.date() == datetime.date.today()
class Admin:
search_fields = ['title','question']
list_display = ('title','pub_date')
list_filter = ['pub_date']
class Choice(models.Model):
poll = models.ForeignKey(Poll, edit_inline=models.STACKED,
min_num_in_admin=0,max_num_in_admin=10,
num_extra_on_change=1)
choice = models.CharField(maxlength=200,core=True)
votes = models.IntegerField(core=True)
def __str__(self):
return self.choice
# class Admin:
# pass
class Interviewee(models.Model):
firstname = models.CharField(maxlength=40,core=True)
lastname = models.CharField(maxlength=40,core=True)
IP = models.IPAddressField()
comments = models.CharField(maxlength=200)
def __str__(self):
return self.firstname +" "+ self.lastname
class Admin:
search_fields =('firstname','lastname')
list_display = ('firstname','lastname')
list_filter = ('firstname','lastname')
class Answer(models.Model):
choice = models.ForeignKey(Choice)
interviewee= models.ForeignKey(Interviewee)
comments = models.CharField(maxlength=200,core=True)
def __str__(self):
return self.choice
class Admin:
pass
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---