Permalink
Browse files

Add in exclusions to get_recommendations

  • Loading branch information...
1 parent 80e9eec commit 3c31fac17a8a1b53628101e7addb8f5db7d775fe @dcramer committed Jun 22, 2010
Showing with 6 additions and 1 deletion.
  1. +6 −1 djangoratings/managers.py
@@ -55,6 +55,7 @@ def get_recommendations(self, user, model_class, min_score=1):
v=Vote._meta.db_table,
sm=self.model._meta.db_table,
m=model_class._meta.db_table,
+ io=IgnoredObject._meta.db_table,
)
objects = model_class._default_manager.extra(
@@ -63,8 +64,12 @@ def get_recommendations(self, user, model_class, min_score=1):
'%(v)s.object_id = %(m)s.id and %(v)s.content_type_id = %%s' % params,
'%(v)s.user_id IN (select to_user_id from %(sm)s where from_user_id = %%s and exclude = 0)' % params,
'%(v)s.score >= %%s' % params,
+ # Exclude already rated maps
+ '%(v)s.object_id NOT IN (select object_id from %(v)s where content_type_id = %(v)s.content_type_id and user_id = %%s)' % params,
+ # IgnoredObject exclusions
+ '%(v)s.object_id NOT IN (select object_id from %(io)s where content_type_id = %(v)s.content_type_id and user_id = %%s)' % params,
],
- params=[content_type.id, user.id, min_score]
+ params=[content_type.id, user.id, min_score, user.id, user.id]
).distinct()
# objects = model_class._default_manager.filter(pk__in=content_type.votes.extra(

0 comments on commit 3c31fac

Please sign in to comment.