Ticket #7904: get_full_query_set.diff

File get_full_query_set.diff, 2.5 KB (added by jbronn, 16 years ago)

Patch from Ivan Sagalaev that offers a different approach.

  • django/db/models/manager.py

     
    5454    def get_empty_query_set(self):
    5555        return EmptyQuerySet(self.model)
    5656
     57    def get_full_query_set(self):
     58        """Returns a new QuerySet object containing all records. Subclasses can
     59        override this method to customize queryset instances but it's required
     60        that they return all records.
     61        """
     62        return QuerySet(self.model)
     63
    5764    def get_query_set(self):
    5865        """Returns a new QuerySet object.  Subclasses can override this method
    59         to easily customize the behavior of the Manager.
     66        to add custom filters to queryset instances.
    6067        """
    61         return QuerySet(self.model)
     68        return self.get_full_query_set()
    6269
    6370    def none(self):
    6471        return self.get_empty_query_set()
     
    8188    def get(self, *args, **kwargs):
    8289        return self.get_query_set().get(*args, **kwargs)
    8390
     91    def get_full(self, *args, **kwargs):
     92        """Used to access parent related objects ensuring that they're
     93        not affected by any filters.
     94        """
     95        return self.get_full_query_set().get(*args, **kwargs)
     96
    8497    def get_or_create(self, **kwargs):
    8598        return self.get_query_set().get_or_create(**kwargs)
    8699
  • django/db/models/fields/related.py

     
    22from django.db.models import signals, get_model
    33from django.db.models.fields import AutoField, Field, IntegerField, PositiveIntegerField, PositiveSmallIntegerField, FieldDoesNotExist
    44from django.db.models.related import RelatedObject
    5 from django.db.models.query import QuerySet
    65from django.db.models.query_utils import QueryWrapper
    76from django.utils.translation import ugettext_lazy, string_concat, ungettext, ugettext as _
    87from django.utils.functional import curry
     
    239238                params = {'%s__pk' % self.field.rel.field_name: val}
    240239            else:
    241240                params = {'%s__exact' % self.field.rel.field_name: val}
    242             rel_obj = QuerySet(self.field.rel.to).get(**params)
     241            rel_obj = self.field.rel.to._default_manager.get_full(**params)
    243242            setattr(instance, cache_name, rel_obj)
    244243            return rel_obj
    245244
Back to Top