Code

Opened 7 years ago

Closed 6 years ago

#3739 closed (fixed)

Add .all() method to QuerySets

Reported by: Jeff Forcier <reg@…> Owned by: nobody
Component: Database layer (models, ORM) Version: master
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: UI/UX:

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@…> 7 years ago.
Diff against checkout of 0.95.1

Download all attachments as: .zip

Change History (9)

Changed 7 years ago by Jeff Forcier <reg@…>

Diff against checkout of 0.95.1

comment:1 Changed 7 years ago by Simon G. <dev@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 7 years ago by Ilya Semenov <semenov@…>

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 Changed 7 years ago by Jeff Forcier <reg@…>

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 Changed 7 years ago by Ilya Semenov <semenov@…>

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 Changed 7 years ago by mtredinnick

  • Keywords qs-rf added
  • Triage Stage changed from Design decision needed to Accepted
  • Version changed from 0.95 to SVN

comment:6 Changed 7 years ago by mtredinnick

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

comment:7 Changed 7 years ago by mtredinnick

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

comment:8 Changed 6 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(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 Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.