Ticket #6901: extra-orderby-2.diff
File extra-orderby-2.diff, 1.3 KB (added by , 17 years ago) |
---|
-
django/db/models/base.py
304 304 manager = cls._default_manager 305 305 if pk_set: 306 306 # Determine whether a record with the primary key already exists. 307 if manager.filter(pk=pk_val).extra(select={'a': 1} ).values('a').order_by():307 if manager.filter(pk=pk_val).extra(select={'a': 1}, order_by=('a',)).values('a'): 308 308 # It does already exist, so do an UPDATE. 309 309 if non_pks: 310 310 values = [(f.name, f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, False))) for f in non_pks] … … 427 427 (qn('_order'), op, qn('_order'), 428 428 qn(self._meta.db_table), qn(self._meta.pk.column))] 429 429 params = [self.pk] 430 obj = self._default_manager.filter(**{order_field.name: getattr(self, order_field.attname)}).extra(where=where, params=params ).order_by(order)[:1].get()430 obj = self._default_manager.filter(**{order_field.name: getattr(self, order_field.attname)}).extra(where=where, params=params, order_by=(order,))[:1].get() 431 431 setattr(self, cachename, obj) 432 432 return getattr(self, cachename) 433 433