我试图将生成的“选择”传递给我的模型字段,请问问题出在哪里?
#models.py
...
def quantity_total():
for x in range(0,100): return "(" + str(x) + "," + str(x) + "),"
QUANTITY = (quantity_total())
class Package(models.Model):
...
...
quantity = models.SmallIntegerField(choices=QUANTITY, max_length=3)
谢谢你们
答案 0 :(得分:3)
choices
应该是2元组的迭代,而不是字符串。
def quantity_total():
return ((x, str(x)) for x in xrange(100))