我正在尝试将对象附加到列表中,但我不断收到错误消息list indices must be integers, not unicode
。这对我来说没有任何意义,因为我没有以任何方式操作列表索引......我只是创建一个新列表并将对象添加到它。
瞧:
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 在模型中具有相似的结构。
提前致谢,