I was able to track down the problem a little further and I saw that Tag.objects.get_for_model(Note, 'foo') | Note.objects.filter(tag='bar')
results in a: "Cannot combine a unique query with a non-unique query" exception. Does anybody have any idea what that means? What is a unique query? On May 22, 7:08 pm, omat <[EMAIL PROTECTED]> wrote: > An other case where I get empty result sets unexpectedly is when I > want to join 2 querysets, one holding the objects that the current > user entered and the other holds the objects marked as favorite by the > current user. > > I have a manager for Favorite objects that takes the model and the > user and returns a queryset for that model that are marked as > favorites by the given user: > > class FavoriteManager(models.Manager): > def get_by_user(self, Model, user): > ctype = ContentType.objects.get_for_model(Model) > rel_table = qn(self.model._meta.db_table) > return Model._default_manager.extra( > tables=[self.model._meta.db_table], # Use a non-explicit join > where=[ > '%s.content_type_id = %%s' % rel_table, > '%s.user_id = %%s' % rel_table, > '%s.%s = %s.object_id' % (qn(Model._meta.db_table), > qn(Model._meta.pk.column), > rel_table) > ], > params=[ctype.id, user.id], > ) > > And when called like this: > Favorite.objects.get_by_user(Note, user) > > the result is a QuerySet containing Note objects which are favorites > of the given user. The structure of the QuerySet is exactly the same > as the result of a query set generated by Note.objects. > > But when I try to get the union such as > > Note.objects.all() | Favorite.objects.get_by_user(Note, user) > > The result is a QuerySet objects with no elemnts in it. > > Thanks... > > On May 22, 4:38 pm, omat <[EMAIL PROTECTED]> wrote: > > > Hi, > > > The "bitwise or" ('|') works fine when taking the union of query sets > > such as: > > Note.objects.filter(tag='foo') | Note.objects.filter(tag='bar') > > > But the result of following is an EmptyQuerySet object: > > Note.objects.filter(tag='foo') | Note.objects.none() > > > Shouldn't it be equivalent to Note.objects.filter(tag='foo'). Am I > > missing something? > > > Thanks, > > omat --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---