所以我有一个Education
附加到UserProfile
. 这个模型的工作原理和一个假设一样:User
已经去了不同地区的几所学校。
我正在尝试做的是根据用户的去向进行“评分”。基本上,如果他们上同一所学校,他们会得到 10 分,同一个城市,5 分,同一个州,2 分,依此类推。
我已经做了一些功能来尝试这个,但我失败了。有什么建议吗?
info = {}
def edu_info(user1):
user_1_cities = []
user_1_schools = []
user_1_state = []
first_one = Education.objects.filter(owner=user1)
for i in first_one:
user_1_cities.append(str(i.city))
user_1_schools.append(str(i.school))
user_1_state.append(str(i.state))
info[str(i.owner.username)] = {}
info[str(i.owner.username)]['cities'] = user_1_cities
info[str(i.owner.username)]['schools'] = user_1_schools
info[str(i.owner.username)]['state'] = user_1_state
return info
def check_match(user1, user2):
match_score = {}
first_info = edu_info(user1)
dict = edu_info(user2)
for item in dict:
cities = dict[item]['cities']
#user2 = item
#print cities
for city in cities:
if city in first_info['jmitchel3']['cities']:
match_score['user'] = 'jmitchel3'
match_score['user2'] = str(user2.user.username)
match_score['city'] = city
print "here! " + str(city)
else:
print "not here! " + str(city)
return match_score
check_match(j,t)