Opened 17 years ago

Closed 16 years ago

#3739 closed (fixed)

Add .all() method to QuerySets

Reported by: Jeff Forcier <reg@…> Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: qs-rf-fixed
Cc: reg@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

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 (1)

queryset_all.diff (656 bytes ) - added by Jeff Forcier <reg@…> 17 years ago.
Diff against checkout of 0.95.1

Download all attachments as: .zip

Change History (9)

by Jeff Forcier <reg@…>, 17 years ago

Attachment: queryset_all.diff added

Diff against checkout of 0.95.1

comment:1 by Simon G. <dev@…>, 17 years ago

Patch needs improvement: set
Triage Stage: UnreviewedDesign decision needed

comment:2 by Ilya Semenov <semenov@…>, 17 years ago

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.

comment:3 by Jeff Forcier <reg@…>, 17 years ago

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 ;)

comment:4 by Ilya Semenov <semenov@…>, 17 years ago

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).

comment:5 by Malcolm Tredinnick, 17 years ago

Keywords: qs-rf added
Triage Stage: Design decision neededAccepted
Version: 0.95SVN

comment:6 by Malcolm Tredinnick, 17 years ago

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

comment:7 by Malcolm Tredinnick, 17 years ago

Keywords: qs-rf-fixed added; qs-rf removed

comment:8 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

(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

Note: See TracTickets for help on using tickets.
Back to Top