[Chicago] 2 unique keys in a python dict?

Martin Maney maney at two14.net
Sat Oct 11 02:19:22 CEST 2008


On Thu, Oct 09, 2008 at 09:39:28PM -0500, Massimo Di Pierro wrote:
> I do not want to insist but I did not get an answer.

Sorry, that was all the answer I could give - to you or to the original
inquiry together.  If I'd realized you really didn't want a solution to
the thread's problem as such but one couched in a restricted way, I
might have avoided most of the effort.  OTOH, mapping the cave was fun,
too.

> How do I write a query in the Django ORM that generates something like  
> "SELECT SUM(....) ... GROUP BY ..." without using SQL explicitly?
>
> I need an example in Django. There is nothing in the Django  
> documentation.

That's because Django does not try to do everything that's possible in
SQL in its ORM.  Since you've read the documentation, I'm sure you've
seen the section titled (in the new, IMO overly fragmented, version)
"Falling back to raw SQL".  It's not as explicit as I thought I
recalled in earlier versions (or perhaps the clearer statement was in
fact elsewhere, not in the organized docs), but the message is: using
raw SQL is (an advanced) part of Django.  The ORM is not designed to do
everything that SQL can do, though it has grown somewhat since it was
originally shared with the world.

I want to note in passing that so far I have found raw SQL useful in a
few very specific places, generally to manage a query that spans
multiple related tables that became too costly when using the
programmatic relational access (thing.other_thing_set, eg.), and using
Django's select_related() would pick up far too much that was not
needed.  It's an escape hatch for special situations, and if you have
to use it all the time then perhaps you need a framework that's better
suited to the kind of work you're doing.  Just notin'

> I would like to show it to my class but I do not know how to do it.

In the narrow sense you're looking for, it can't, to the best of my
knowledge.

> P.S. Incidentally I know how to do in postscript (as you suggest), in  
> fact I did create this library for drawing in postscript (and yes, this 
> is stupid, but 12 years ago it seemed like a good idea):

I may be misremembering, but I think that at least briefly, when it was
new, my first Laserjet had more RAM than the PC it was attached to -
certainly it had at least a large fraction as much.  Under those
circumstances, I thought it made perfect sense to write a roff-like
text formatter in postscript.  (if nothing else, that finessed the lack
of readily available font metrics, at least in a form I understood.)  I
always loved RPN in the context of those wonderful old HP calculators,
but in a larger context it was... well, I never would have thought this
at the time, but it was somewhat like a foretaste of the way you have
to twist your thinking to code in assembler on some RISC-ish
microcontrollers, eg., Microchip's PIC family.  Or the twisted
framework. <wink>

-- 
There is overwhelming evidence that the higher the level of self-esteem,
the more likely one will be to treat others with respect, kindness, and
generosity. -- Nathaniel Branden



More information about the Chicago mailing list