Corss posted from stack overflow<http://stackoverflow.com/questions/15923809/django-queryset-in-operator-fails-on-first-call>
When using the 'in' operator on a queryset, the first time the call is made it fails. from django.db import models class Category(models.Model): name = models.CharField(max_length=100) class Project(models.Model): categories = models.ManyToManyField(Category, related_name='projects') category_list = Category.objects.prefetch_related('projects') print category_list # [<Category: Category object>, <Category: Category object>]print category_list[0] in category_list # Falseprint category_list[0] in category_list # True If I remove 'prefetch_related' and use 'all' instead then the problem is gone, however this uses many more DB calls. How can I get the correct result first time using prefetch_related? -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.