Last active
August 29, 2015 14:05
-
-
Save mtomwing/af4504269e10e3c9fb78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def editData(self, qid, qcontent, answerList): | |
## Update the question content | |
q = Question.objects.get(id = qid) | |
q.content = qcontent | |
q.save() | |
## Add/Modify Answers | |
i = 1 | |
for ans in answerList.split("/"): | |
try: | |
tempAnswer = Answer.objects.get(qid = q.id, number = i) | |
tempAnswer.content = ans | |
except: | |
tempAnswer = Answer(qid = q.id, content = ans, number = i) | |
tempAnswer.save() | |
i += 1 | |
## Remove any Answers that are no longer included | |
while i <= 5: | |
try: | |
tempAnswer = Answer.objects.get(qid = q.id, number = i) | |
tempAnswer.delete() | |
except: | |
pass | |
i += 1 | |
answers = Answer.objects.all() | |
answerJS = [{"Question": ((Question.objects.get(id = q.qid)).content), "content": q.content, "AnswerNumber": q.number} for q in answers] | |
return HttpResponse(simplejson.dumps(answerJS)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment