-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

モデルはすべて同じなので、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 に答える