我有以下几点:
answers = Answer.objects.filter(id__in=[answer.id for answer in answer_set.answers.all()])
之后:
for i in range(len(answers)):
# iterate through all existing QuestionAnswer objects
for existing_question_answer in existing_question_answers:
# if an answer is already associated, remove it from the
# list of answers to save
if answers[i].id == existing_question_answer.answer.id:
answers.remove(answers[i]) # doesn't work
existing_question_answers.remove(existing_question_answer)
我得到一个错误:
'QuerySet' object has no attribute 'remove'
我已经尝试了各种方法将QuerySet转换为标准集或列表。没有什么工作。
我怎么能从QuerySet中删除一个项,这样它就不会从数据库中删除它,也不会返回一个新的QuerySet(因为它在一个循环中,不会工作)?