I’m trying to append an object to a list, and I keep getting the error list indices must be integers, not unicode. It doesn’t make any sense to me, as I’m not manipulating the list indices in any way… I’m just creating a new list and append()ing objects to it.
Voila:
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
Assume for the sake of this example that NewLesson and EachLesson have similar structures in the model.
Thanks in advance,
Well, the big hint is the only place you’ve done a getitem call:
mdays[month]If you had to convert
monthto anintin other places,monthis most likely a string causing the error oncalendar.mdays[month]Otherwise, it’s a call elsewhere that your traceback would have identified. My money is on
mdays[month]though due to theint(month)elsewhere.