-1

我有一组模型 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"
4

1 回答 1

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()
于 2012-08-16T13:24:12.977 回答