Ticket #24141: queryset-contains.diff

File queryset-contains.diff, 676 bytes (added by gormster, 10 years ago)

db/models/query.py diff

  • django/db/models/query.py

    diff --git a/django/db/models/query.py b/django/db/models/query.py
    index 6774fee..37ae072 100644
    a b class QuerySet(object):  
    577577        if self._result_cache is None:
    578578            return self.query.has_results(using=self.db)
    579579        return bool(self._result_cache)
     580   
     581    def contains(self, obj):
     582        if self._result_cache is not None:
     583            return obj in self._result_cache
     584        return isinstance(obj, self.model) and self.filter(pk=obj.pk).exists()
    580585
    581586    def _prefetch_related_objects(self):
    582587        # This method can only be called once the result cache has been filled.
Back to Top