2008-8-4

23:22 FunkyBob
try the "new" module... standard python module
23:22 FunkyBob
or there's getattr and globals
23:23 Kilarney
FunkyBob: eval method doesn't require importing any extra code - but yes it's ugly :)
23:23 Q45
new.classobj(str) ?
23:24 FunkyBob
Q45: why do you have the object name in a string?
23:26 Q45
i've got something where i have a class with several descendants, and i need to decide which descendant to use
23:26 Q45
something like the factory pattern
23:26 Kilarney
jinzo: I meant upon ModelForm.save, not when populating the ModelForm itself
23:27 Kilarney
I can see how you wouldn't want ModelForm to always fill in the current user, but it seems much more likely to me that you would want that behavior, so perhaps a toggle defaulting to true
23:27 SmileyChris
Kilarney: because the current user is tied to a request, and a form isn't
23:28 Kilarney
ahh, true
23:28 Zalamander
Q45 getattr(module_name, class_name)
23:28 Zalamander
er, that should be module, not module_name
23:28 Q45
what if it's in the current module? use __main__?
23:29 Kilarney
globals() or locals(), depending on the scope
23:29 Zalamander
Q45 dont' do it in the current module, or use an explicit dictionary in which to look up eligible classes.
23:29 Zalamander
"__main__" is a name, not a module
23:30 Zalamander
(sorry if I confused that issue above)
23:33 FunkyBob
yeah... I prefer to create an explicit mapping dict
23:33 FunkyBob
it's simpler, safer, and clearer
23:34 Zalamander
or a separate module. Either way creates a contained namespace
23:36 Q45
mapping dict = {'Object': Object} ?
23:36 FunkyBob
yep
23:36 FunkyBob
then you can do foo = mapping_dict.get( mystring, DefaultObject)
23:37 Q45
is there a way to get a list of all of the subclasses of a class that have been defined?
23:38 FunkyBob
probably
23:39 FunkyBob
you dig deep enough, you can find anything :P
23:39 Q45
but you need to know where to dig
23:39 Zalamander
Q45 YourClass.__subclasses__
23:39 Q45
sweet
23:40 Q45
hmm tried it, didn't work
23:42 Q45
ah, everything has to descend from object
23:42 Zalamander
yes, ultimately
23:42 Q45
right
23:43 Q45
ok, this does exactly what i need
23:44 stp2007
I understand that django under DEBUG mode keeps a copy of all queries made. However looking at the total of these queries I get an obvious different running total depending on what view I'm looking at. Does django retain these per view or app?
23:45 Zalamander
stp2007 per request, most likely
23:49 stp2007
Zalamander, that makes sense. my code needs some review to explain why my query count rises in a view. hmm.
23:54 FunkyBob
stp2007: there's some nice snippets on django snippets to give you a dump of queries (and their execution time) for a view
Page 39 of 39   ← Previous  (3,839 total)