オブジェクトをリストに追加しようとしていますが、エラーが発生し続けます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がモデル内で同様の構造を持っていると仮定します。
前もって感謝します、