Ticket #7231: extra-join-1.1b.2.diff

File extra-join-1.1b.2.diff, 2.6 KB (added by tomas@…, 6 years ago)

Modified extra join which will not interfere with django multilingual.

  • django/db/models/sql/query.py

     
    9393        self.extra_where = ()
    9494        self.extra_params = ()
    9595        self.extra_order_by = ()
     96        self.extra_join_123 = ()
    9697
    9798        # A tuple that is a set of model field names and either True, if these
    9899        # are the fields to defer, or False if these are the only fields to
     
    211212        obj.extra_where = self.extra_where
    212213        obj.extra_params = self.extra_params
    213214        obj.extra_order_by = self.extra_order_by
     215        obj.extra_join_123 = self.extra_join_123
    214216        obj.deferred_loading = deepcopy(self.deferred_loading)
    215217        if self.filter_is_sticky and self.used_aliases:
    216218            obj.used_aliases = self.used_aliases.copy()
     
    390392        result.append('FROM')
    391393        result.extend(from_)
    392394        params.extend(f_params)
     395       
     396        if self.extra_join_123:
     397            result.append(' '.join(self.extra_join_123))
    393398
    394399        if where:
    395400            result.append('WHERE %s' % where)
     
    20952100        self.related_select_cols = []
    20962101        self.related_select_fields = []
    20972102
    2098     def add_extra(self, select, select_params, where, params, tables, order_by):
     2103    def add_extra(self, select, select_params, where, params, tables, order_by, join=None):
    20992104        """
    21002105        Adds data to the various extra_* attributes for user-created additions
    21012106        to the query.
     
    21282133            self.extra_tables += tuple(tables)
    21292134        if order_by:
    21302135            self.extra_order_by = order_by
     2136        if join:
     2137            self.extra_join_123 += tuple(join)
    21312138
    21322139    def clear_deferred_loading(self):
    21332140        """
  • django/db/models/query.py

     
    570570        return obj
    571571
    572572    def extra(self, select=None, where=None, params=None, tables=None,
    573               order_by=None, select_params=None):
     573              order_by=None, select_params=None, join=None):
    574574        """
    575575        Adds extra SQL fragments to the query.
    576576        """
    577577        assert self.query.can_filter(), \
    578578                "Cannot change a query once a slice has been taken"
    579579        clone = self._clone()
    580         clone.query.add_extra(select, select_params, where, params, tables, order_by)
     580        clone.query.add_extra(select, select_params, where, params, tables, order_by, join)
    581581        return clone
    582582
    583583    def reverse(self):
Back to Top