I think a choice field is probably best, then you can customize the
presentation in a forms file.
class Question(models.Model):
q_cjoices = (
('choice1', 'choice1'),
('choice2', 'choice2'),
('choice3', 'choice3'),
('choice4', 'choice4'),
('choice5', 'choice5'),
)
title = modelsForeignKey(Title)
choices = models.CharField(choices=q_choices, max_length=100)
In the form declaration you can use this
from models.Questions import q_choices
from django.forms.extras.widgets import RadioSelect
choices = forms.CharField(choices=q_choices, widget=RadioSelect)
That would work unless you want someone to be able add choices based
on individual questions in which case you'll need to use a many to
many field, something like this:
Question(models.Model)
title = models.ForeignKey(Title)
Choice = models.ManyToManyField(Choice)
class Choice(models.CharField)
choice_1 = models.CharField( etc. etc. etc.
On Jul 12, 4:21 pm, rupert <[email protected]> wrote:
> Thanks for replying.
>
> I'm ultimately trying to create a feedback form where there is a list
> of say 10 questions with 5 choices for response to each question. It
> also needs to be editable in the admin (and I can't get forms to be
> editable in the admin).
>
> On Jul 12, 5:11 pm, Rodion Raskolnikiv <[email protected]> wrote:
>
> > Rupert,
> > Without knowing what you are aiming to accomplish, my advice might not
> > be pertinent. However, it looks like your models could be rearranged
> > like this:
>
> > class Question(models.Model):
> > question = models.CharField(max_length=200)
> > pub_date = models.DateTimeField('date published')
>
> > class Choice(models.Model):
> > poll = models.ForeignKey(Question)
> > choice = models.CharField(max_length=200)
> > votes = models.IntegerField()
>
> > (Slightly modified from:http://docs.djangoproject.com/en/dev/intro/
> > tutorial01/)
>
> > On Jul 12, 1:49 pm, rupert <[email protected]> wrote:
>
> > > For this code:
>
> > > class Title(models.Model):
> > > title = models.CharField(max_length=200)
> > > pub_date = models.DateTimeField('date published')
>
> > > def __unicode__(self):
> > > return self.title
>
> > > def was_published_today(self):
> > > return self.pub_date.date() == datetime.date.today()
>
> > > class Question(models.Model):
> > > title = models.ForeignKey(Title)
> > > question = models.CharField(max_length=200)
> > > choice1 = models.CharField(max_length=200)
> > > choice2 = models.CharField(max_length=200)
> > > choice3 = models.CharField(max_length=200)
> > > choice4 = models.CharField(max_length=200)
> > > choice5 = models.CharField(max_length=200)
>
> > > def __unicode__(self):
> > > return self.question
>
> > > I'm trying to write a view where it outputs like this
>
> > > Question
>
> > > Choice 1-choice 5 in a radio button
--
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.