Hello! I have the following code:
class Comment(models.Model): VISIBILITY_PUBLIC = 'pub' VISIBILITY_PRIVATE = 'private' VISIBILITY_FRIENDS = 'friends' VISIBILITY_CHOICES = ( (VISIBILITY_PUBLIC, 'Public'), (VISIBILITY_PRIVATE, 'Private'), (VISIBILITY_FRIENDS, 'Friends'), ) author = models.ForeignKey(User) content = models.ForeignKey('Entity') is_important = models.BooleanField() visibility = models.CharField(max_length=10, choices=VISIBILITY_CHOICES) class Entity(models.Model): name = models.CharField(max_length=100) objects = EntityManager() class EntityManager(models.Manager): def visible_comments(self, user, only_own=True): friends = get_friends(user) filter_expr = {} q_expr = Q() qs = self.get_query_set() q_expr |= (Q(comment__privacy=Comment.VISIBILITY_PUBLIC) | Q(comment__privacy=Comment.VISIBILITY_FRIENDS, comment__user__in=friends)) if not only_own: q_expr |= Q(comment__user=user) else: filter_expr.update({'comment__user': user}) qs = qs.filter(q_expr, **filter_expr) # This code duplicates objects with is_important == True in qs qs = qs.extra(select={'is_important': 'comments_comment.is_important'}).distinct() The effect is that: 1. qs.count() return 50 elements 2. iteration like for el in qs: (...) returns for example 55 elements: 50 el + number of important elements 3. when last line is removed then it's 50 in count and 50 in iteration. The code is run on Django 1.4. What's wrong here? Best regards Jakub -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9dd05fa9-186c-49b2-b8ee-46a29ba76c5c%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.