ic_fl2 ic_fl2 -4 years ago 78
SQL Question

Saving a data stream in a django project

I'm working on a django website project where logged in users are answering questions. I want to store the answers of all users, collecting which user answered, what answer they gave and what question got asked as well as some data on when it was answered etc. I guess this qualifies as stream.

How should I go about this? Just write a model to enter the data to a table and give all users the permission to write to that table? Are there better solutions as I heard that writing to a sql db too often isn't good.

Currently I do the following in views.py:

answer_instance = Answer.objects.create(user=request.user,
question_text = question_text,
correct_text = correct_answer,
answer_text = student_answer,
time_taken = str(min(round(float(time_taken),1),999)), time_answered = now() # evaluate date time when record is created
)


and in models.py these are defined as Char, Integer or DateTime fields. But this view is called after each question, and I think it would be better to only write to the database after each quiz, or is that inconsequential.

Answer Source

So what I was looking for is called @commit_on_success as described here: Aggregating save()s in Django?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download