我试图追加一个对象到列表中,并且我一直收到错误list indices must be integers, not unicode。它对我来说没有任何意义,因为我不以任何方式操纵列表索引......我只是创建一个新列表并向其中添加()ing对象。
瞧:
def read(self, request, uid, month, year):
qs = NewLesson.objects.filter(student__teacher = request.user).filter(endDate__gte=date(int(year), int(month), 1)).filter(startDate__lte=datetime.date(int(year), int(month), calendar.mdays[month]))
lessonList = []
qsList = list(qs)
for l in qsList:
if l.frequency == 0:
x = EachLesson()
x.lessonID = l.id
x.actualDate = l.startDate
x.student = l.student
lessonList.append(x)
else:
sd = next_date(l.startDate, l.frequency, datetime.date(int(year), int(month), 1))
while (sd <= date(int(year), int(month), calendar.mdays[month])):
x = EachLesson()
x.lessonID = l.id
x.actualDate = sd
x.student = l.student
lessonList.append(x)
sd += datetime.timedelta(recurrence)
return lessonList假设为了这个例子,NewLesson和EachLesson在模型中具有相似的结构。
提前致谢,