#25326 closed New feature (fixed)
Add an example with namedtuple to "Executing custom SQL directly"
Reported by: | Dražen Odobašić | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Namedtuples can be used to provide more convenient access for custom SQL Results. This PR adds an example for namedtuple wrapper function and shows differences between normal (tuple), dict and namedtuple wrapper functions.
Change History (6)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
Couple of remarks:
- examples are Python2 as
'id': 54360982L
, in Python3 all integers are implemented aslong
integers and as we are pushing Python3, we should probably change it - as
cursors
are iterable examples could be improved in a way to not usefetchall()
but return a generator, and then use list comprehensions to actually show the difference between approaches
comment:3 by , 9 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → New feature |
Looks reasonable, but docs should assume Python 3. Haven't taken time to understand point 2, but if you want to make those updates as a separate commit, I'll take a look. After you make the updates, please uncheck "Patch needs improvement" on the ticket so it returns to the review queue. Thanks!
comment:4 by , 9 years ago
Patch needs improvement: | unset |
---|
Pull request: https://github.com/django/django/pull/5206