diff --git a/django_facebook/__init__.py b/django_facebook/__init__.py index 0a9c688b..c27f43f3 100644 --- a/django_facebook/__init__.py +++ b/django_facebook/__init__.py @@ -4,7 +4,7 @@ __license__ = 'BSD' -__version__ = '3.6.2' +__version__ = '3.6.3' __maintainer__ = 'Thierry Schellenbach' __email__ = 'thierryschellenbach@gmail.com' __status__ = 'Production' diff --git a/django_facebook/model_managers.py b/django_facebook/model_managers.py index 4e64c36d..ad15cc2b 100644 --- a/django_facebook/model_managers.py +++ b/django_facebook/model_managers.py @@ -34,19 +34,22 @@ def random_facebook_friends(self, user, gender=None, limit=3): assert gender in (None, 'M', 'F'), 'Gender %s wasnt recognized' % gender from django_facebook.utils import get_profile_class - facebook_cache_key = 'fusers_%s' % user.id - new_facebook_users = cache.get(facebook_cache_key) + facebook_cache_key = 'facebook_users_%s' % user.id + non_members = cache.get(facebook_cache_key) profile_class = get_profile_class() - if not new_facebook_users: + if not non_members: facebook_users = list(self.filter(user_id=user.id, gender=gender)[:50]) facebook_ids = [u.facebook_id for u in facebook_users] - new_facebook_users = list(profile_class.objects.filter(facebook_id__in=facebook_ids).select_related('user')) - cache.set(facebook_cache_key, new_facebook_users, 60*60) + members = list(profile_class.objects.filter(facebook_id__in=facebook_ids).select_related('user')) + member_ids = [p.facebook_id for p in members] + non_members = [u for u in facebook_users if u.facebook_id not in member_ids] - random_limit = min(len(new_facebook_users), 3) + cache.set(facebook_cache_key, non_members, 60*60) + + random_limit = min(len(non_members), 3) random_facebook_users = [] if random_limit: - random_facebook_users = random.sample(new_facebook_users, limit) + random_facebook_users = random.sample(non_members, limit) return random_facebook_users \ No newline at end of file diff --git a/django_facebook/models.py b/django_facebook/models.py index 0f93bcaa..e5480396 100644 --- a/django_facebook/models.py +++ b/django_facebook/models.py @@ -68,6 +68,9 @@ class FacebookUser(models.Model): class Meta: unique_together = ['user_id', 'facebook_id'] + + def __unicode__(self): + return u'Facebook user %s' % self.name class FacebookLike(models.Model):