Code

Opened 6 years ago

Closed 6 years ago

Last modified 4 years ago

#7479 closed (duplicate)

Improve dictionary (dict()) support in QuerySets

Reported by: wim@… Owned by: nobody
Component: Validators Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Being a happy-dictionary-user I would love it if Django gave them more support. Two opportunities spring into mind:

  1. Model.objects.filter(id=1).values() does not support many-to-many fields. I feel like it should do so and return their ids as a list, like in: 'key': [1, 2, 3] . Because many-to-many fields are in the declaration of the model, and in the .filter()-results, I believe they should be represented in the .values()-dictionary as well.
  1. I really miss .values() in Model.objects.get(id=1), which to me seems asymmetric.

Thanks for giving this a thought. For me, dictionaries and lists are a very friendly and native way of handling data in Python. They can easily represent complex data structures while staying comprehensible. I hope they make you happy too.

Attachments (0)

Change History (5)

comment:1 Changed 6 years ago by telenieko

  • milestone set to post-1.0
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from I love dictionaries to Improve dictionary (dict()) support in QuerySets

That's post-1.0 also set a Summary that doesn't seem like spam in the reports :)
Dunno if Design Decision of Accepted thought... we'll see.

comment:2 Changed 6 years ago by ericholscher

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 6 years ago by mtredinnick

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

"Django doesn't use my favourite language feature enough" isn't really a bug report.

The first part is a upe of #5768 and it isn't nearly as simple as it looks on the surface. The second part doesn't need anything done, since filter(id=1).values(...)[0] works exactly as expected.

Going to mark as a duplicate for the first part, but we're suffering from the usual problem that when two different things are in a single ticket, no single resolution works.

comment:4 Changed 5 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:5 Changed 4 years ago by adrian_nye

It would be nice to document under values() that it does not work with get(), and the workaround using filter().

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.