目前我有 3 个数据存储类
用户活动研讨会
每个研讨会都引用一个事件,每个事件只有四个研讨会
在用户类中,我有一个列表属性,我在其中引用每个用户所属的研讨会的键。
我希望每个用户只参加一个研讨会活动。
@classmethod
def event_attendance(self, user):
workshop1 = self.workshops.filter('workshop_number =', 1).get(keys_only = True)
users1 = User.all().filter('attendance =', workshop1.key()).fetch(149)
if user in users1:
return True
else:
workshop2 = self.workshops.filter('workshop_number =', 2).get(keys_only = True)
users2 = User.all().filter('attendance =', workshop2.key()).fetch(149)
if user in users2:
return True
else:
workshop3 = self.workshops.filter('workshop_number =', 3).get(keys_only = True)
users3 = User.all().filter('attendance =', workshop3.key()).fetch(149)
if user in users3:
return True
else:
workshop4 = self.workshops.filter('workshop_number =', 4).get(keys_only = True)
users4 = User.all().filter('attendance =', workshop4.key()).fetch(149)
if user in users4:
return True
else:
return False
在这里,我查看了一个活动,看看用户是否参加了任何一个研讨会,并使用下面的方法找出他们是否参加了这个活动的研讨会,以找到哪个。
@classmethod
def My_Event(self, user):
workshop1 = self.workshops.filter('workshop_number =', 1).get(keys_only = True)
users1 = User.all().filter('attendance =', workshop1.key()).fetch(149)
if user in users1:
return workshop1
else:
workshop2 = self.workshops.filter('workshop_number =', 2).get(keys_only = True)
users2 = User.all().filter('attendance =', workshop2.key()).fetch(149)
if user in users2:
return workshop2
else:
workshop3 = self.workshops.filter('workshop_number =', 3).get(keys_only = True)
users3 = User.all().filter('attendance =', workshop3.key()).fetch(149)
if user in users3:
return workshop3
else:
workshop4 = self.workshops.filter('workshop_number =', 4).get(keys_only = True)
users4 = User.all().filter('attendance =', workshop4.key()).fetch(149)
if user in users4:
return workshop4
我对 appengine 很陌生,实际上对编程很陌生(主要是自学)
考虑到我必须以这种方式检查每个事件以查看是否附加了用户,这感觉非常昂贵,有没有办法用我当前的数据建模结构更有效地做到这一点,或者我应该改变它吗???