Django

Code

Ticket #3739 (closed: fixed)

Opened 1 year ago

Last modified 3 weeks ago

Add .all() method to QuerySets

Reported by: Jeff Forcier <reg@bitprophet.org> Assigned to: nobody
Component: Database wrapper Version: SVN
Keywords: qs-rf-fixed Cc: reg@bitprophet.org
Triage Stage: Accepted Has patch: 1
Needs documentation: 0 Needs tests: 0
Patch needs improvement: 1

Description

Per Google Groups discussion here, I've found that it would be nice if QuerySets? exhibited a .all() method so that custom instance-level model methods which return QuerySets? could be treated as if they were regular relationship-generated Manager objects.

The attached patch adds this to 0.95.1 and I can put together a unittest if needed.

Attachments

queryset_all.diff (0.6 kB) - added by Jeff Forcier <reg@bitprophet.org> on 03/15/07 17:08:30.
Diff against checkout of 0.95.1

Change History

03/15/07 17:08:30 changed by Jeff Forcier <reg@bitprophet.org>

  • attachment queryset_all.diff added.

Diff against checkout of 0.95.1

03/15/07 17:54:19 changed by Simon G. <dev@simon.net.nz>

  • needs_better_patch set to 1.
  • stage changed from Unreviewed to Design decision needed.
  • needs_tests changed.
  • needs_docs changed.

03/28/07 13:34:05 changed by Ilya Semenov <semenov@inetss.com>

How comes you write directly under this comment:

# PUBLIC METHODS THAT ALTER ATTRIBUTES AND RETURN A NEW QUERYSET # 
################################################################## 

and your function does not return a new queryset? This is misleading and makes the code worse.

03/28/07 13:44:43 changed by Jeff Forcier <reg@bitprophet.org>

Well, it doesn't fit too well in any of the other marked sections either:

  • PYTHON MAGIC METHODS - nope
  • METHODS THAT DO DATABASE QUERIES - Doesn't do any extra querying
  • PUBLIC METHODS THAT RETURN A QUERYSET SUBCLASS - Doesn't technically return a subclass in the same way that these methods do
  • PRIVATE METHODS - nope

I felt that it "fit in" best with filter, exclude, order_by and friends, since those are all the most commonly-used methods of Managers/QuerySets.

If you have a better suggestion of where to put it, I'm all ears, although I don't see how it "makes the code worse", though, that's just hyperbole ;)

03/29/07 00:40:12 changed by Ilya Semenov <semenov@inetss.com>

How about changing the comment to say:

# PUBLIC METHODS THAT MOSTLY ALTER ATTRIBUTES AND RETURN A NEW QUERYSET #

or similar change?

Sorry, I wasn't trying to offend, I just really feel that when the code is not doing what it says is generally a bad thing (since eventually this decreases the code quality).

10/21/07 14:25:18 changed by mtredinnick

  • keywords set to qs-rf.
  • version changed from 0.95 to SVN.
  • stage changed from Design decision needed to Accepted.

10/23/07 08:49:08 changed by mtredinnick

(In [6600]) queryset-refactor: Added a convenience all() method to Querysets. Refs #3739

10/23/07 08:51:18 changed by mtredinnick

  • keywords changed from qs-rf to qs-rf-fixed.

04/26/08 21:50:16 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(In [7477]) Merged the queryset-refactor branch into trunk.

This is a big internal change, but mostly backwards compatible with existing code. Also adds a couple of new features.

Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658


Add/Change #3739 (Add .all() method to QuerySets)




Change Properties
Action