views:

31

answers:

1

Looking for some implementation ideas here. I am trying to design a custom polling system for my school, to allow teachers to give students polls to take.

I have a Poll model, Question model (with a foreignkey to Poll model), and Choice model (with a foreignkey to the Question model).

What I need to be able to do is allow whoever is adding questions to choose the type of choices that will be shown. For example, one question should be able to be multiple choice (displayed via a radio buttons), and another question should be able to be "Check all that apply."

What is the best way to allow the creator of the poll to determine how the choices are shown? Should I do a CharField() with choices, and deal with it manually in the view? That doesn't seem efficient.

+2  A: 

Use a field in your model that has choices for the different ways people can choose (it doesn't have to be CharField, you could also use a SmallIntegerField and map numbers). Create different form classes for each way of choosing and decide in the view which one to apply based on the value of the "way of choosing"-field. It's a straight-forward way and not that much of a hassle if abstracted nicely.

stefanw
Thanks. This seems like it will work, I'll give it a shot later today.
CodeBlock