Commit Graph

253 Commits

Author SHA1 Message Date
Anssi Kääriäinen d5b93d3281 Fixed #10494 -- Added kwargs to QuerySet.get() error message in the case no objects were found.
Thanks brondsem for the report, Szymon Pyzalski for the patch and oinopion for review.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@17917 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2012-04-20 11:09:32 +00:00
Aymeric Augustin 632b6a1a73 Fixed #17439 -- Prevented spurious queries for missing objects after prefetch_related has run.
That affects nullable foreign key, nullable one-to-one, and reverse one-to-one relations.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@17899 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2012-04-11 21:11:22 +00:00
Karen Tracey 9d98b9eb4b Fix #17876: Corrected an exception (regression) raised where select_realted and only is used on a proxy model. Thanks milosu and charettes.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17692 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2012-03-12 22:33:18 +00:00
Luke Plant de9942a667 Fixed #17668 - prefetch_related does not work in in_bulk
Thanks to gurets for the report, and akaariai for the initial patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17600 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2012-02-28 19:34:04 +00:00
Julien Phalip 31b1cbc623 Fixed #16340 -- Made `get_or_create()` re-raise any `IntegrityError` with its original traceback. Thanks to d0ugal and Jonas Obrist.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17333 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2012-01-02 21:30:47 +00:00
Ramiro Morales 287565779d Added support for modifying the effect of ``DISTINCT`` clauses so they
only consider some fields (PostgreSQL only).

For this, the ``distinct()`` QuerySet method now accepts an optional
list of model fields names and generates ``DISTINCT ON`` clauses on
these cases. Thanks Jeffrey Gelens and Anssi Kääriäinen for their work.

Fixes #6422.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17244 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 20:42:40 +00:00
Adrian Holovaty 073d987a84 Fixed #16818 -- Fixed ORM bug with many-to-many add() method where it wasn't committing the change. Thanks, pressureman and kmtracey
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17189 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-09 23:16:56 +00:00
Adrian Holovaty 5f9dbef4bb Fixed #17335 -- Added supports_select_related hook for django-nonrel. Thanks, jonash
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17170 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-05 23:11:43 +00:00
Luke Plant f2ebb169f9 Small code clarification in prefetch_related code using better variable names
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17162 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-11-29 12:50:10 +00:00
Luke Plant 64da8eec30 Fixed #17014 - added protection against infinite recursion.
Thanks to akaariai for the report and tests.

No tests have been added, since unittests for termination are basically
impossible, and the failure condition will take down the developer's machine
in this case. It has been tested against the cases in #17014.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16940 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-10-07 16:06:02 +00:00
Luke Plant 052a011ee6 Fixed #17003 - prefetch_related should support foreign keys/one-to-one
Support for `GenericForeignKey` is also included.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16939 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-10-07 16:05:53 +00:00
Luke Plant 662eea116f Fixed #16937 - added `QuerySet.prefetch_related` to prefetch many related objects.
Many thanks to akaariai for lots of review and feedback, bug finding,
additional unit tests and performance testing.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16930 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-10-05 23:14:52 +00:00
Luke Plant d30fbf8b78 Fixed #16902 - select_related() results in a poor perfomance
Thanks to ivan_virabyan for the great patch!

(For the record, some very small tweaks were made by me).

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16929 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-10-05 22:56:09 +00:00
Alex Gaynor 345c4c4629 Remove a bunch of deadcode/dead imports.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16794 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-09-10 22:31:38 +00:00
Alex Gaynor b45a4acf6f Ensure bulk_create returns the right value if the argument is an empty list.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16792 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-09-10 21:46:59 +00:00
Alex Gaynor f2bc919ec0 Ensure bulk_create returns what it is supposed to.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16791 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-09-10 21:44:57 +00:00
Alex Gaynor 7deb25b8dd Fixed #7596. Added Model.objects.bulk_create, and make use of it in several places. This provides a performance benefit when inserting multiple objects. THanks to Russ for the review, and Simon Meers for the MySQl implementation.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16739 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-09-09 19:22:28 +00:00
Jannis Leidel 50ed810c1f Fixed #16472 -- Removed stale code in the query code. Thanks, fva@chtd.org.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16562 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-07-29 09:40:09 +00:00
Jannis Leidel 24f4764a48 Fixed #16225 -- Removed unused imports. Many thanks to Aymeric Augustin for the work on the patch and Alex for reviewing.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16539 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-07-13 09:35:51 +00:00
Ramiro Morales b2050ff546 Fixed #16409 -- Fixed an error condition when using QuerySet only()/defer() on the result of an annotate() call. Thanks jaklaassen AT gmail DOT com and Tai Lee for the reports and Tai for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16522 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-07-07 01:12:45 +00:00
Ramiro Morales a8598c7de2 Fixed #11789 -- Fixed aggregates so it interacts with QuerySet none() in a way consistent with other empty query sets. Thanks alexr for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16254 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-05-21 16:54:25 +00:00
Jannis Leidel c77372cad0 Fixed #14729 -- RawQuerySet.__repr__ fails when params passed as list. Thanks, intgr for ticket and accuser for patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16088 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-04-22 18:17:26 +00:00
Jannis Leidel a845eba8dd Fixed #11283 -- Made sure that latest() clears previously specified ordering in a QuerySet. Thanks to benmoran, punteney, mk and and Julien Phalip.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16067 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-04-22 12:02:07 +00:00
Jacob Kaplan-Moss 8f0f73c7b8 Fixed #2705: added a `select_for_update()` clause to querysets.
A number of people worked on this patch over the years -- Hawkeye, Colin Grady,
KBS, sakyamuni, anih, jdemoor, and Issak Kelly. Thanks to them all, and
apologies if I missed anyone.

Special thanks to Dan Fairs for picking it up again at the end and seeing this
through to commit.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16058 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-04-20 20:42:07 +00:00
Adrian Holovaty d546179c71 Fixed incorrect usage of its in query.py docstring
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16024 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-04-11 20:27:53 +00:00
Adrian Holovaty 13864703bc Removed a bunch more Python 2.4 workarounds now that we don't support that version. Refs #15702 -- thanks to jonash for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15927 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-03-28 02:11:19 +00:00
Adrian Holovaty 15295a852f Fixed #15647 -- Changed in_bulk() not to type check its input, which now allows for passing any iterable. Thanks, calvinspealman
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15922 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-03-26 17:50:10 +00:00
Russell Keith-Magee 337a6bc0f6 Fixed #15283 -- Made a minor performance tweak to __iter__. Thanks to lanyjie for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15491 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-02-12 05:23:41 +00:00
Russell Keith-Magee 340eaded4e Fixed #15116 -- Strip ordering clause from in_bulk() queries, since ordering information will be lost. Thanks to lamby for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15457 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-02-08 14:05:38 +00:00
Russell Keith-Magee ae8ff5f476 Fixed #14707 -- Relax the protections on aggregate naming collisions when a ValuesQuerySet removes the colliding name. Thanks to Andy McKay for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15223 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-01-16 08:03:25 +00:00
Andrew Godwin ea774bf9a7 Fix wrong attribute name in [15156]. Thanks to Alex Gaynor for spotting this.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15169 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-01-10 13:44:35 +00:00
Andrew Godwin 81e05a418d Fixed #9029 -- Allow use of fieldname_id with get_or_create. Thanks to aaron and mrmachine.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15156 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-01-08 13:27:30 +00:00
Alex Gaynor d68598e022 Fixed #14700 -- ensure that a raw query is only executed once per iteration.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14785 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-12-03 20:25:59 +00:00
Alex Gaynor 678f626c24 Fixed a suite of errors in the ORM -- a) fixed calling values_list().values_list() and changing whether the results are flat, b) fixed an issue with fields on the left-hand side of what becomes the HAVING clause not being included in the GROUP BY clause, and c) fixed a bug with fields from values() calls not being included in the GROUP BY clause. This fixed the recent test failures under postgresql.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14715 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-11-26 14:24:08 +00:00
Luke Plant 073412b411 Fixed #14700 - speed up RawQuerySet iterator.
This moves constant work out of the loop, and uses the much faster *args
based model instantiation where possible, to produce very large speed ups.

Thanks to akaariai for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14692 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-11-24 15:26:29 +00:00
Luke Plant ff7c243b4c Fixed #14697 - speeded up model instance creation by moving work outside of loops
Thanks to akaariai for the report and initial patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14687 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-11-23 13:54:58 +00:00
Carl Meyer 9b432cb67b Fixed #5768 -- Added support for ManyToManyFields and reverse relations in values() and values_list(). Thanks to mrmachine for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14655 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-11-21 02:28:25 +00:00
Carl Meyer 008f333bac Fixed pk uniqueness validation for new objects created outside of a ModelForm. Also removed need for ModelForm to poke at Model._state.adding, keeping it an internal ORM concern.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14613 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-11-18 23:29:58 +00:00
Carl Meyer 616b30227d Fixed #7539, #13067 -- Added on_delete argument to ForeignKey to control cascade behavior. Also refactored deletion for efficiency and code clarity. Many thanks to Johannes Dollinger and Michael Glassford for extensive work on the patch, and to Alex Gaynor, Russell Keith-Magee, and Jacob Kaplan-Moss for review.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14507 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-11-09 16:46:42 +00:00
Alex Gaynor abaa3ed4bd Fixed #13935, added support for using QuerySet.dates across related fields. Thanks to valyagolev for his work on the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14461 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-11-04 16:03:05 +00:00
Alex Gaynor c38a174f7c Remove several uses of the deprecated dict.has_key in favor of the in operator. This is faster, has less code, and is in every single way better.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14392 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-10-29 04:24:53 +00:00
Carl Meyer 2f17dd3dd0 Refs #11256 -- Extended the annotation field name conflict check to cover m2ms and reverse related descriptors as well. This is needed to actually cover the case raised by #14373.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14116 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-10-10 08:04:14 +00:00
Carl Meyer 1fe1af93a5 Added sanity-checking of annotation alias names.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14092 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-10-09 20:07:48 +00:00
Alex Gaynor 560fedde4c Fixed #14366 -- Model.objects.none().values() now correctly returns a QuerySet with no items, rather than raising an Exception. Thanks to Carl Meyer for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14084 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-10-09 16:45:58 +00:00
Jannis Leidel efac677add Fixed #14280 -- Fixed duplicate import of deepcopy. Thanks, Carl Meyer.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13877 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-09-26 22:59:44 +00:00
Russell Keith-Magee 7e06065d8b Fixed #13552 -- Added a 'using' parameter to database signals. Thanks to gmandx for the suggestion, and Andrew Godwin for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13538 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-08-07 06:27:52 +00:00
Russell Keith-Magee 8b1aebbf35 Fixed #12851 -- Another attempt at fixing select_related() with inherited models, this time with only(). Thanks to phxx for the test case.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13059 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-04-30 16:32:48 +00:00
Russell Keith-Magee e93f56b174 Fixed #13227 -- Ensure that the query cache is flushed when a QuerySet is deepcopied, avoiding problems when an evaluated queryset is used as a subquery. Thanks to claudep for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12970 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-04-13 15:18:10 +00:00
Russell Keith-Magee 040c18b17e Fixed #13309 -- Ensure that delete() deletes everything it should delete(). Thanks to craig.kimerer@gmail.com for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12941 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-04-09 13:24:13 +00:00
Russell Keith-Magee 82efb48403 Fixed #12328 -- Corrected the handling of subqueries with ordering and slicing, especially when used in delete subqueries. Thanks to Walter Doekes for the report.
This fixes a feature that isn't available under MySQL and Oracle (Refs #10099).

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12912 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-04-04 17:05:43 +00:00
Russell Keith-Magee f7cf58ac0e Fixed #12429 -- Ensure that raw queries call resolve_columns if the backend defines it. This ensures (as much as possible) that the model values returned by a raw query match that in normal queries. Thanks to Ian Kelly for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12904 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-04-01 16:48:16 +00:00
Russell Keith-Magee 3a5dae5ed3 Fixed #12851 -- Corrected the interaction of defer() with select_related(). Thanks to ruosteinen for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12817 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-03-20 15:37:26 +00:00
Russell Keith-Magee bfa080f402 Fixed #12937 -- Corrected the operation of select_related() when following an reverse relation on an inherited model. Thanks to subsume for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12814 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-03-20 15:02:59 +00:00
Russell Keith-Magee 2d57300f52 Fixed #12953 -- Ensure that deletion cascades through generic relations. Also cleans up the special-casing of generic relations in the deleted object discovery process. Thanks to carljm for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12790 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-03-15 13:15:01 +00:00
Russell Keith-Magee d312fa2a61 Fixed #12717 -- Corrected a problem with subqueries when using multidb routing. Thanks to Jeff Balogh for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12755 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-03-10 15:27:22 +00:00
Russell Keith-Magee 18983f0ee7 Fixed #13003 -- Ensured that ._state.db is set correctly for select_related() queries. Thanks to Alex Gaynor for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12701 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-03-07 07:13:55 +00:00
Joseph Kocherhans c05de31d75 Fixed #12731. Fixed a bug with .raw() and inheritance. Thanks, Alex Gaynor.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12544 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-02-23 19:39:06 +00:00
Joseph Kocherhans 65b451ae3e Fixed #12819. Fixed a bug with caching values of nullable 1to1 fields. Thanks, s.angel@twidi.com for the initial patch, and Alex Gaynor for the tests.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12543 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-02-23 19:24:27 +00:00
Justin Bronn 5546430304 Fixed #12608 -- No longer return inconsistent results when using `values` and `values_list` in conjunction with `annotate`. Thanks, Charlie Leifer.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12505 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-02-23 05:26:49 +00:00
Justin Bronn c4699b0b8a Fixed #12806 -- Added an implementation of `RawQuerySet.__getitem__`. Thanks, Bruno Renié.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12504 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-02-23 05:22:12 +00:00
Russell Keith-Magee 58cd220f51 Fixed #7270 -- Added the ability to follow reverse OneToOneFields in select_related(). Thanks to George Vilches, Ben Davis, and Alex Gaynor for their work on various stages of this patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12307 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-01-27 13:30:29 +00:00
Russell Keith-Magee 1b3dc8ad9a Fixed #12540, #12541 -- Added database routers, allowing for configurable database use behavior in a multi-db setup, and improved error checking for cross-database joins.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12272 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-01-22 14:30:06 +00:00
Adrian Holovaty 5ceed0a053 Changed a whole bunch of places to raise exception instances instead of old-style raising exception classes plus a comma. Good for the future Python 3 conversion
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12180 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-01-10 18:36:20 +00:00
Adrian Holovaty cf1b6845d4 Fixed #12142 -- EmptyQuerySet.update() no longer updates all rows in the database
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12171 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-01-10 17:53:19 +00:00
Adrian Holovaty 2dd9a85819 Fixed #7235 -- EmptyQuerySet no longer raises and exception when it's filter()ed (along with some other QuerySet methods). Thanks, taylormarshall
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12147 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2010-01-09 21:27:39 +00:00
Ian Kelly cdf5ad4217 Changes to get raw queries working on the oracle backend.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11968 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-12-22 21:05:15 +00:00
Russell Keith-Magee ff60c5f9de Fixed #1142 -- Added multiple database support.
This monster of a patch is the result of Alex Gaynor's 2009 Google Summer of Code project.
Congratulations to Alex for a job well done.

Big thanks also go to:
 * Justin Bronn for keeping GIS in line with the changes,
 * Karen Tracey and Jani Tiainen for their help testing Oracle support
 * Brett Hoerner, Jon Loyens, and Craig Kimmerer for their feedback.
 * Malcolm Treddinick for his guidance during the GSoC submission process.
 * Simon Willison for driving the original design process
 * Cal Henderson for complaining about ponies he wanted.

... and everyone else too numerous to mention that helped to bring this feature into fruition.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11952 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-12-22 15:18:51 +00:00
Jacob Kaplan-Moss 20ad30713e Fixed #11863: added a `Model.objects.raw()` method for executing raw SQL queries and yield models.
See `docs/topics/db/raw.txt` for details.

Thanks to seanoc for getting the ball rolling, and to Russ for wrapping things up.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11921 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-12-20 02:46:58 +00:00
Luke Plant e4757ec7af Fixed #12258 - QuerySet.get() should clear ordering.
We only clear ordering when doing so cannot change the result returned by
the get() method i.e.  when the query does not already define limits.

Thanks to mattdennewitz@gmail.com for the report, and jdunck for the patch



git-svn-id: http://code.djangoproject.com/svn/django/trunk@11916 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-12-19 15:02:46 +00:00
Luke Plant 7efd96844d Fixed #12251 - QuerySet.in_bulk() should accept set/frozenset
Thanks to emulbreh for patch.



git-svn-id: http://code.djangoproject.com/svn/django/trunk@11915 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-12-19 14:50:41 +00:00
Jacob Kaplan-Moss 574eafe4c0 Fixed #11753 - Q objects with callables no longer explode on Python 2.4. Thanks, Jeremy Dunck.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11901 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-12-17 22:06:41 +00:00
Luke Plant eeb10d5f2c Optimised use of 'in' operator on QuerySet using an explicit __contains__ method.
Without this change, use of 'in' on a QuerySet resulted in ._result_cache
being fully populated, which sometimes is unnecessary work.



git-svn-id: http://code.djangoproject.com/svn/django/trunk@11803 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-12-09 16:07:21 +00:00
Russell Keith-Magee 585b7acaa3 Fixed #10109 -- Removed the use of raw SQL in many-to-many fields by introducing an autogenerated through model.
This is the first part of Alex Gaynor's GSoC project to add Multi-db support to Django.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11710 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-11-03 14:02:49 +00:00
Jacob Kaplan-Moss b79702b2de Fixed #11402: added a `QuerySet.exists()` method. Thanks, Alex Gaynor.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11646 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-10-24 00:28:39 +00:00
Russell Keith-Magee 151d88af4e Fixed #11082 -- Ensured that subqueries used in an exclude(X__in=) clause aren't pre-evaluated. Thanks to Henry Andrews for the report, and clement for the fix.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10929 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-06-06 13:35:33 +00:00
Russell Keith-Magee 512ee0f528 Fixed #10572 -- Corrected the operation of the defer() and only() clauses when used on inherited models.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10926 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-06-06 06:14:05 +00:00
Russell Keith-Magee 2416e5fefe Fixed #9479 -- Corrected an edge case in bulk queryset deletion that could cause an infinite loop when using MySQL InnoDB.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10913 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-06-03 13:23:19 +00:00
Russell Keith-Magee b9b9ca334e Fixed #9308 -- Corrected the updated of nullable foreign key fields when deleting objects. Thanks to Bob Thomas for the fix, and markshep for the improvements on the test case.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10822 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-05-19 12:44:17 +00:00
Russell Keith-Magee 5e2d38465a Fixed #10847 -- Modified handling of extra() to use a masking strategy, rather than last-minute trimming. Thanks to Tai Lee for the report, and Alex Gaynor for his work on the patch.
This enables querysets with an extra clause to be used in an __in filter; as a side effect, it also means that as_sql() now returns the correct result for any query with an extra clause.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10648 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-04-30 15:40:09 +00:00
Jacob Kaplan-Moss c00e8d2064 Added a `QuerySet.ordered` property to check if a queryset is already ordered. Refs #10163.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10623 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-04-22 22:16:19 +00:00
Malcolm Tredinnick 0a89a57ffc Fixed deferred fields and select_related() interaction.
Loading related models when some fields were deferred was resulting in
incorrect offsets being used into the results row, causing the wrong data to be
assigned to attributes.

Refs #10710. This fixes the first of two bugs reported there.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10383 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-04-04 05:34:23 +00:00
Malcolm Tredinnick dded5f52cc Fixed #10695 -- Fixed implementation of deferred attribute retrieval.
The original implementation had a few silly bugs in it that meant that data was
not being used only on the instance of the class that it was appropriate for
(one of the traps when using class-level things). No more!

Thanks to Justin Bronn and Alex Gaynor for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10382 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-04-04 03:21:31 +00:00
Malcolm Tredinnick 014b961509 Typo fix for an error path in r100090.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10091 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-19 09:43:45 +00:00
Malcolm Tredinnick 29050ef999 Fixed #5420 -- Added support for delayed loading of model fields.
In extreme cases, some fields are expensive to load from the database
(e.g. GIS fields requiring conversion, or large text fields). This
commit adds defer() and only() methods to querysets that allow the
caller to specify which fields should not be loaded unless they are
accessed.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10090 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-19 09:06:04 +00:00
Malcolm Tredinnick 5fb6667036 Fixed #3460 -- Added an ability to enable true autocommit for psycopg2 backend.
Ensure to read the documentation before blindly enabling this: requires some
code audits first, but might well be worth it for busy sites.

Thanks to nicferrier, iamseb and Richard Davies for help with this patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10029 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-11 07:06:50 +00:00
Malcolm Tredinnick 3242df16e4 To avoid an unfortunately common user-error, rename QuerySet.as_sql().
This was never a public API method, so this is backwards compatible, unless
you're poking at the internals. Refs #10352.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9928 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-03-01 04:12:30 +00:00
Russell Keith-Magee 542709d0d1 Fixed #10182 -- Corrected realiasing and the process of evaluating values() for queries with aggregate clauses. This means that aggregate queries can now be used as subqueries (such as in an __in clause). Thanks to omat for the report.
This involves a slight change to the interaction of annotate() and values() clauses that specify a list of columns. See the docs for details.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9888 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-02-23 14:47:59 +00:00
Russell Keith-Magee fb64ea7896 Fixed #10132 -- Corrected the interaction of extra() queries with the values() clause. Thanks to Glen Maynard for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9838 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-02-16 12:29:31 +00:00
Russell Keith-Magee 58ea6d4561 Fixed #10256 -- Corrected the interaction of extra(select=) with values() and values_list() where an explicit list of columns is requested.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9837 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-02-16 12:28:37 +00:00
Russell Keith-Magee d4a3a4b0ca Fixed #10199 -- Modified aggregate() calls to clone the base query so that the base query can be reused. Thanks to Alex Gaynor for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9819 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-02-08 11:14:07 +00:00
Russell Keith-Magee ecadf67569 Fixed #10127 -- Corrected (no, really, this time!) the way the select_related() cache is populated when annotations are also contained in the query. Thanks to Sylvain Pasche <sylvain.pasche@gmail.com> for the report and test case.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9808 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-02-03 11:07:21 +00:00
Russell Keith-Magee 8f410a577b Fixed #10127 -- Corrected handling of select_related() in annotate() calls. Thanks to Sylvain Pasche <sylvain.pasche@gmail.com> for the report and test case.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9805 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-02-02 13:43:18 +00:00
Malcolm Tredinnick d579e716fe Fixed #9997 -- Fixed use of ValuesQuerySets as rvalues in filters.
Previous behaviour was pretty stupid. Let's never speak of it again. New
behaviour both works and is documented.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9759 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-01-16 10:59:43 +00:00
Russell Keith-Magee cc4e4d9aee Fixed #3566 -- Added support for aggregation to the ORM. See the documentation for details on usage.
Many thanks to:
 * Nicolas Lara, who worked on this feature during the 2008 Google Summer of Code.
 * Alex Gaynor for his help debugging and fixing a number of issues.
 * Justin Bronn for his help integrating with contrib.gis.
 * Karen Tracey for her help with cross-platform testing.
 * Ian Kelly for his help testing and fixing Oracle support.
 * Malcolm Tredinnick for his invaluable review notes.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9742 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-01-15 11:06:34 +00:00
Malcolm Tredinnick c5bdfab9ae Fixed #9985 -- qs.values_list(...).values(...) was constructing incorrect SQL.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9717 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-01-08 05:49:03 +00:00
Malcolm Tredinnick d068ad0c01 Using querysets as an rvalue in filter() calls was causing an unnecessary
database query, due to a bool() call. This change stops that behaviour.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9715 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-01-08 05:16:21 +00:00
Malcolm Tredinnick f747b61c20 Nested query support.
This extends previous functionality that allowed passing Query objects as the
rvals to filters. You can now pass QuerySets, which requires less poking at
opaque attributes. See the documentation of the "__in" lookup type for the
details.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9701 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2009-01-05 11:47:48 +00:00
Malcolm Tredinnick 44f228fd61 Fixed #6748 -- When printing the repr() of querysets, don't load or display
more than 20 objects.

This means that accidentally executing HugeStoryArchive.objects.all() at the
interactive prompt (or in the debug template) won't try to load all 4,233,010
stories into memory and print them out. That would previously cause resource
starvation and other "interesting" crashes.

If you really, really want the previous behaviour (e.g. in a doctest that
prints more than 20 items), display "list(qs)" instead of just "qs".


git-svn-id: http://code.djangoproject.com/svn/django/trunk@9202 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-10-08 08:38:33 +00:00
Jacob Kaplan-Moss 7ecdf47bd0 Fixed #8115: avoid a infiniate loop when collecting related objects for deletion.
I can't reproduce the original error leading to #8115 and the patch. However, the only harm this change could cause is to raise more `CyclicDependency` exceptions than strictly necessary. That's better than infinite loops, at least, and it's easier to clean up in the future when we figure out the actual fix.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8807 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-09-01 19:35:03 +00:00
Malcolm Tredinnick 51836756d0 Fixed a typo from the refactoring in [8455]. With bonus test, too. Thanks, vung.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8724 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2008-08-29 22:29:38 +00:00