Ticket #7231: extra-join-1.0.diff

File extra-join-1.0.diff, 2.4 KB (added by Davide "Design" Muzzarelli <info@…>, 16 years ago)

New parameter "join" for the QuerySet.extra() function. For Django-1.0.

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

     
    8585        self.extra_where = ()
    8686        self.extra_params = ()
    8787        self.extra_order_by = ()
     88        self.extra_join = ()
    8889
    8990    def __str__(self):
    9091        """
     
    187188        obj.extra_where = self.extra_where
    188189        obj.extra_params = self.extra_params
    189190        obj.extra_order_by = self.extra_order_by
     191        obj.extra_join = self.extra_join
    190192        if self.filter_is_sticky and self.used_aliases:
    191193            obj.used_aliases = self.used_aliases.copy()
    192194        else:
     
    277279        result.append('FROM')
    278280        result.extend(from_)
    279281        params.extend(f_params)
     282       
     283        if self.extra_join:
     284            result.append(' '.join(self.extra_join))
    280285
    281286        if where:
    282287            result.append('WHERE %s' % where)
     
    16251630        self.related_select_cols = []
    16261631        self.related_select_fields = []
    16271632
    1628     def add_extra(self, select, select_params, where, params, tables, order_by):
     1633    def add_extra(self, select, select_params, where, params, tables, order_by, join):
    16291634        """
    16301635        Adds data to the various extra_* attributes for user-created additions
    16311636        to the query.
     
    16581663            self.extra_tables += tuple(tables)
    16591664        if order_by:
    16601665            self.extra_order_by = order_by
     1666        if join:
     1667            self.extra_join += tuple(join)
    16611668
    16621669    def trim_extra_select(self, names):
    16631670        """
  • django/db/models/query.py

     
    567567        return obj
    568568
    569569    def extra(self, select=None, where=None, params=None, tables=None,
    570               order_by=None, select_params=None):
     570              order_by=None, select_params=None, join=None):
    571571        """
    572572        Adds extra SQL fragments to the query.
    573573        """
    574574        assert self.query.can_filter(), \
    575575                "Cannot change a query once a slice has been taken"
    576576        clone = self._clone()
    577         clone.query.add_extra(select, select_params, where, params, tables, order_by)
     577        clone.query.add_extra(select, select_params, where, params, tables, order_by, join)
    578578        return clone
    579579
    580580    def reverse(self):
Back to Top