Hi guys,

I'm going to develop a survey application with the following
functionalities:

•An administrator defines a custom form through a form builder
interface to carry out a survey. The form can be composed of an
arbitrary number of questions (the form of text boxes, radio and check
boxes only).  The only field that will always be present is the email
address of the respondent.
•The form is displayed to the respondents
•The respondents fill the form and the data are saved in the database

While I have a rough idea on how the form builder should look like
(http://jacobian.org/writing/dynamic-form-generation/), I struggle to
figure out which is the best approach to save the data back in the
database (ie, how the model should look like).

I figured out 3 possible approaches:
1. save each answer to each question of each survey as a separate
record in the database, using a model like, eg, email_address,
survey_id, answer.

2. save each form of each survey as a separate record in the database.
Assuming that the number of question will be always, let’s say, lower
than 50, I could create a model like email_address, survey_id,
answer_to_question_1, …, answer_to_question_50 and use only the first
n fields, depending on how many questions the specific survey has

3. Create a dynamic model. Once the form structure has been defined by
the administrator -assuming is not going to be modified anymore once
saved - I could create a new model and the corresponding table in the
db, named eg  survey_id with the exact fields that I need to save the
form.

I feel the approach 3) quite unsafe and difficult to implement since I
need to give the admin the ability to create and delete tables of the
db.
The approach 1) seems to be the most flexible, although this means
ending up with huge tables in terms of rows. I can easily expect 30
000 respondents per year and 10 to 15 questions per survey. This means
to have a table with 450 000 records in a single year, which could
some question marks on performances.
The approach 2) seems to be the most performance oriented. However,
since I need to save the answers from textboxes, radio and checkboxes,
I’ll end up to a model with 50 fields defined as CharField with let’s
say max_lenght=100, so the table will be quite huge in terms of
columns even if a lot of records will use only a limited amount of the
available columns (ie, there will be a lot of columns without a real
need).

I’m not a super expert of DB and Django ORM performances. Taking into
consideration the options above and the fact that, at the end I’ll
need to run queries over the DB to get reports on the answers for a
given survey, what do you suggest? Is there any other approach I’m
missing?

Thanks for your help.

Cheers,

P.

-- 
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.

Reply via email to