Django

Code

Changeset 7031

Show
Ignore:
Timestamp:
01/27/08 05:17:33 (7 months ago)
Author:
mtredinnick
Message:

queryset-refactor: Added the ability to use a subclass of WhereNode? in queries. Also allow extension of the permitted lookup terms. Both of these are drive by geo-django requirements, but should be generally useful. Thanks, Justin Bronn.

Fixed #6261.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/queryset-refactor/django/db/models/sql/query.py

    r6967 r7031  
    7878 
    7979    alias_prefix = 'T' 
    80  
    81     def __init__(self, model, connection): 
     80    query_terms = QUERY_TERMS 
     81 
     82    def __init__(self, model, connection, where=WhereNode): 
    8283        self.model = model 
    8384        self.connection = connection 
     
    9293        self.select = [] 
    9394        self.tables = []    # Aliases in the order they are created. 
    94         self.where = WhereNode() 
     95        self.where = where() 
     96        self.where_class = where 
    9597        self.group_by = [] 
    9698        self.having = [] 
     
    157159        obj.tables = self.tables[:] 
    158160        obj.where = copy.deepcopy(self.where) 
     161        obj.where_class = self.where_class 
    159162        obj.group_by = self.group_by[:] 
    160163        obj.having = self.having[:] 
     
    193196        obj.select_related = False 
    194197        if obj.distinct and len(obj.select) > 1: 
    195             obj = self.clone(CountQuery, _query=obj, where=WhereNode(), 
     198            obj = self.clone(CountQuery, _query=obj, where=self.where_class(), 
    196199                    distinct=False) 
    197200            obj.select = [] 
     
    320323            # rhs has an empty where clause. Make it match everything (see 
    321324            # above for reasoning). 
    322             w = WhereNode() 
     325            w = self.where_class() 
    323326            alias = self.join((None, self.model._meta.db_table, None, None)) 
    324327            pk = self.model._meta.pk 
    325328            w.add(EverythingNode(), AND) 
    326329        else: 
    327             w = WhereNode() 
     330            w = self.where_class() 
    328331        self.where.add(w, connector) 
    329332 
     
    705708 
    706709        # Work out the lookup type and remove it from 'parts', if necessary. 
    707         if len(parts) == 1 or parts[-1] not in QUERY_TERMS
     710        if len(parts) == 1 or parts[-1] not in self.query_terms
    708711            lookup_type = 'exact' 
    709712        else: 
     
    11101113            if not isinstance(related.field, generic.GenericRelation): 
    11111114                for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE): 
    1112                     where = WhereNode() 
     1115                    where = self.where_class() 
    11131116                    where.add((None, related.field.m2m_reverse_name(), 
    11141117                            related.field, 'in', 
     
    11181121 
    11191122        for f in cls._meta.many_to_many: 
    1120             w1 = WhereNode() 
     1123            w1 = self.where_class() 
    11211124            if isinstance(f, generic.GenericRelation): 
    11221125                from django.contrib.contenttypes.models import ContentType 
     
    11251128                        ContentType.objects.get_for_model(cls).id), AND) 
    11261129            for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE): 
    1127                 where = WhereNode() 
     1130                where = self.where_class() 
    11281131                where.add((None, f.m2m_column_name(), f, 'in', 
    11291132                        pk_list[offset : offset + GET_ITERATOR_CHUNK_SIZE]), 
     
    11421145        """ 
    11431146        for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE): 
    1144             where = WhereNode() 
     1147            where = self.where_class() 
    11451148            field = self.model._meta.pk 
    11461149            where.add((None, field.column, field, 'in', 
     
    11861189        """ 
    11871190        for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE): 
    1188             where = WhereNode() 
     1191            where = self.where_class() 
    11891192            f = self.model._meta.pk 
    11901193            where.add((None, f.column, f, 'in',