Ticket #7231: extra-join.diff

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

New parameter "join" for the QuerySet.extra() function.

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

     
    8282        self.extra_where = ()
    8383        self.extra_params = ()
    8484        self.extra_order_by = ()
     85        self.extra_join = ()
    8586
    8687    def __str__(self):
    8788        """
     
    182183        obj.extra_where = self.extra_where
    183184        obj.extra_params = self.extra_params
    184185        obj.extra_order_by = self.extra_order_by
     186        obj.extra_join = self.extra_join
    185187        obj.__dict__.update(kwargs)
    186188        if hasattr(obj, '_setup_query'):
    187189            obj._setup_query()
     
    261263        result.append('FROM')
    262264        result.extend(from_)
    263265        params.extend(f_params)
     266       
     267        if self.extra_join:
     268            result.append(' '.join(self.extra_join))
    264269
    265270        if where:
    266271            result.append('WHERE %s' % where)
     
    13791384        self.related_select_cols = []
    13801385        self.related_select_fields = []
    13811386
    1382     def add_extra(self, select, select_params, where, params, tables, order_by):
     1387    def add_extra(self, select, select_params, where, params, tables, order_by, join):
    13831388        """
    13841389        Adds data to the various extra_* attributes for user-created additions
    13851390        to the query.
     
    14011406            self.extra_tables += tuple(tables)
    14021407        if order_by:
    14031408            self.extra_order_by = order_by
     1409        if join:
     1410            self.extra_join += tuple(join)
    14041411
    14051412    def trim_extra_select(self, names):
    14061413        """
  • django/db/models/query.py

     
    448448        return obj
    449449
    450450    def extra(self, select=None, where=None, params=None, tables=None,
    451             order_by=None, select_params=None):
     451            order_by=None, select_params=None, join=None):
    452452        """
    453453        Add extra SQL fragments to the query.
    454454        """
    455455        assert self.query.can_filter(), \
    456456                "Cannot change a query once a slice has been taken"
    457457        clone = self._clone()
    458         clone.query.add_extra(select, select_params, where, params, tables, order_by)
     458        clone.query.add_extra(select, select_params, where, params, tables, order_by, join)
    459459        return clone
    460460
    461461    def reverse(self):
Back to Top