【发布时间】:2017-02-26 11:57:03
【问题描述】:
我正在用 django (v1.10.5) 和 python 制作一个在线剧院预订应用程序。
models.py:
TheaterLocation = [
(1, 'Naharlagun'),
]
FloorLevel = [
(1, 'Ground Floor'),
(2, 'Balcony'),
]
Row = [
]
Column = [
]
class Seat(models.Model):
theater_location = models.PositiveIntegerField(choices=TheaterLocation)
floor_level = models.PositiveIntegerField(choices=FloorLevel)
row_id = models.PositiveIntegerField()
column_id = models.PositiveIntegerField()
@property
def seat_id(self):
return "%s : %s : %s : %s" % (self.theater_location, self.floor_level, self.row_id, self.column_id)
我想做的是,像这样自动为Row 和Column 创建一个选项列表:
Row = [
(1, 'A'),
(2, 'B'),
...
...
(8, 'H'),
]
Column = [
1,2,3,4,5, ... , 22
]
我怎样才能像上面那样实现?
【问题讨论】:
-
我很困惑。 “自动”是什么意思?
-
@hashcode55 我想使用 shell 或模板中的函数创建行和列。