Code

Opened 7 years ago

Closed 6 years ago

#3168 closed enhancement (wontfix)

[patch] object_list should accept lists as well as QuerySets

Reported by: Grimboy Owned by: nobody
Component: Generic views Version:
Severity: normal Keywords:
Cc: frankie@… Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description

object_list should accept lists as well as QuerySets. This is perhaps a matter of opinion. Obviously getting access to a list in urls.py isn't practical. However, lots of people use generic views as a way to "finish off" real views. It therefore seems a bit limiting to only accept QuerySets. A view may parse some items in an xml file and return them as a list or may do a raw SQL query rather than using Django's ORM. So this is not an impractical addition.

I haven't renamed the queryset argument since it is often specified by keyword. Another, perhaps cleaner solution would be to rename queryset to sequence and accept queryset as a deprecated (or not) argument.

Attachments (4)

patch.diff (3.4 KB) - added by Grimboy 7 years ago.
object_list_accept_list.diff (2.7 KB) - added by Grimboy 7 years ago.
Using documentation conventions.
object_list_accept_list_v2.diff (4.0 KB) - added by frankie@… 7 years ago.
This version doesn't force what obviously aren't QuerySets to be passed in by queryset=* while keeping compatibility. Not sure if this is more or less confusing than the previous one.
object_list_accept_list_v3.diff (4.1 KB) - added by frankie@… 7 years ago.
Fixed silly bug from using if foo rather than if foo is not None. Against [4750].

Download all attachments as: .zip

Change History (11)

Changed 7 years ago by Grimboy

Changed 7 years ago by Grimboy

Using documentation conventions.

Changed 7 years ago by frankie@…

This version doesn't force what obviously aren't QuerySets to be passed in by queryset=* while keeping compatibility. Not sure if this is more or less confusing than the previous one.

comment:1 Changed 7 years ago by anonymous

  • Cc frankie@… added

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

  • Triage Stage changed from Unreviewed to Design decision needed

comment:3 Changed 7 years ago by Gary Wilson <gary.wilson@…>

Please note that #3181 was marked a duplicate of this and had an alternative patch.

comment:4 Changed 7 years ago by ubernostrum

I'd be +1 on this since it would mean generic views could work with other ORMs.

comment:5 Changed 7 years ago by frankie@…

So we are currently +3 (me, arockstar@… of the other patch and ubernostrum) and -0. Anyone going to object or should this be moved onto ready for checkin?

Changed 7 years ago by frankie@…

Fixed silly bug from using if foo rather than if foo is not None. Against [4750].

comment:6 Changed 7 years ago by SmileyChris

  • Patch needs improvement set

I much prefer the version before another keyword was introduced.

Needs improvement because it should be using isinstance(queryset, QuerySet) in case it's a subclass.

comment:7 Changed 6 years ago by jacob

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

No, this is by design: generic views operate on querysets. If you need different behavior, you'll need to write your own views.

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.