Skip to content

Instantly share code, notes, and snippets.

@mtomwing
Last active August 29, 2015 14:05
Show Gist options
  • Save mtomwing/af4504269e10e3c9fb78 to your computer and use it in GitHub Desktop.
Save mtomwing/af4504269e10e3c9fb78 to your computer and use it in GitHub Desktop.
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