我有一套模型Day1,...,Day7。 如何使用1-7的整数来使用正确的模型?
class Day1 (db.Model): #Monday
courtday = db.ReferenceProperty(CourtDays)
startTime = db.TimeProperty()
endTime = db.TimeProperty()
startTimeLunch = db.TimeProperty()
endTimeLunch = db.TimeProperty()
day = "Monday"
class Day2 (db.Model): #Tuesday
courtday = db.ReferenceProperty(CourtDays)
startTime = db.TimeProperty()
endTime = db.TimeProperty()
startTimeLunch = db.TimeProperty()
endTimeLunch = db.TimeProperty()
day = "Tuesday"
答案 0 :(得分:1)
一天只需要一个型号,因为它们都是一样的。
class Day (db.Model):
courtday = db.ReferenceProperty(CourtDays)
startTime = db.TimeProperty()
endTime = db.TimeProperty()
startTimeLunch = db.TimeProperty()
endTimeLunch = db.TimeProperty()
name = db.StringProperty()
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
for dayname in days:
newday = Day(name=dayname)
newday.put()