python附加索引_附加到列表返回“列表索引必须是整数,而不是unicode”(django / python)...

我试图追加一个对象到列表中,并且我一直收到错误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在模型中具有相似的结构。

提前致谢,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值