views:

39

answers:

1

i want to create a form for users to submit questions in django ..so far the models i have created are

class Question(models.Model):
    statement=models.CharField(max_length=100)  
class Choice(models.Model):
    statement=models.CharField(max_length=100)
    value=models.IntegerField()
    question=models.ForeignKey(Question)

Now i want to write a Form class for creating a above form but the problem is the number of choices are variable,a user can decide how many choices a question must have .How do i do that in django?

A: 

You can go ahead and create any number of choices per question.

All the choices that are there on a given question can be retrieved by question.choice_set.all()

It is one of the most basic ORM query. I suggest you go thro' the django tutorial

Update:

You need to use a modelformset for this.

Lakshman Prasad
yeah i understad that but what i am askin is about form object what should the form object loook like ?
Bunny Rabbit