これはおそらく、より一般的な Python クエリです。
たとえば、特別な文字列値の整数表現を返すメソッドを追加して、GAE の db.Property クラスの 1 つを継承および拡張しようとしました。
class DbHHMM(db.StringProperty):
def to_mins(self):
'''Convert the string to minutes'''
arr = re.split(":",self)
ret = 0.0
if (len(arr)==2):
ret = (int(arr[0])*60)+(int(arr[1]))
return ret;
私のモデルでは、一連のこれらの値を合計するメソッドがあります。
class WorkSchedule(db.Model):
'''todo - core hours for the days
TODO is there any way to attach a widgeted form to these via newform = WorkScheduleForm() '''
time1 = DbHHMM()
time2 = DbHHMM()
total = db.IntegerProperty
def sum_times:
self.total = time1.to_mins + time2.to_mins
ただし、 sum_times が呼び出されると、エラーが発生するようです:
AttributeError: 'unicode' object has no attribute 'to_mins'
GAE プロパティ クラスに追加のメソッドを追加することは可能ですか?これを防ぐために使用されている Python の手法は何ですか? 私は何か完全に間違っていますか?