Howdy, I'm trying to construct a dynamic query that, given a list of number ranges, will find all instances of a ModelObject myNumber where an integer value is between any of those ranges. Do I create some filter object, then use the |= operator for the lower and upper number in my range to construct my filter?
zxq9
EagleOne: For now, encode/decode. For later, explore utf8 and url handling in Django. If you've spent time on this then the cost of typing 20 more letters is trivial.
EagleOne
yep..
umc has quit
Gorroth has quit
Gorroth joined the channel
ohrstrom has quit
monokrome joined the channel
ben_nicoll has quit
abisson has quit
brainwarped_m has quit
dsb has quit
zxq9
Scottyob: You can use Q objects with a logical OR, and add them together iteratively. So break the ranges provided into a list, for example, then do something like { for i in ranges:; query |= Q(i); }.
aberrant has quit
Scottyob: The whole idea is that you can tack more Q objects onto each other using the |= operator, and then feed the result to a filter() method.
Scottyob
zxq9: what does the |= operator do? Creates the OR?
aberrant joined the channel
napperjabber has quit
zxq9
Scottyob: That will generate SQL similar to "SELECT * FROM foo WHERE (a > x1 AND a < y1) OR (b > x2 AND b y2)" (it might even generate a range function, but regardless, you get the idea)
eternicode
|= is bitwise OR
er, bitwise OR-equal.
jdunck has quit
(not that there's a non-bitwise OR-equal)
karansag_ joined the channel
zxq9
Scottyob: The |= operator is the old C bitwise "OR equals" but in Python it seems to work in a more general sense.
karansag has quit
Scottyob
oh right. Good stuff. So just build my q = model.objects.filter(number__gte=rangeLower, number__lte=rangeUpper); q |= model.objects.filter(number__gte=rangeLower2, number__lte=rangeUpper2)....
ljubak has quit
sorry, that was a question
cheshair joined the channel
Raisins has quit
jSanp has quit
md4d joined the channel
cheshair
Hi! Where am I supposed to place my templates folder with Django 1.4? Does it make any sense to have a general/main templates folder at the root of my django folder? Or should I try and rely only on app-specific templates?
karansag has quit
mritz joined the channel
Ixbidie has quit
md4d has quit
rns
does anyone know how to mask django form field inputs? I want to format them as currenecy, but submit them as Decimals still.
hwrd|work has quit
Scottyob
yeah, that works perfect. Thanks zxq9, eternicode :)
n3storm joined the channel
andrewjsledge has quit
chachan joined the channel
gabrielfalcao has quit
gabrielfalcao joined the channel
gremly has quit
zandauxzan has left the channel
kristallpirat has quit
estebistec has quit
kristallpirat joined the channel
dennis_m joined the channel
mritz has quit
kristallpirat has quit
kristallpirat joined the channel
hwrd|work joined the channel
Raisins joined the channel
matthewlmcclure has quit
ender979 has quit
mogga has left the channel
davidfischer has quit
NomadJim has quit
notanumber
Very interesting. Bit the bullet and rewrote using (proper) aggregation and not only does it work, but it's much faster. Heh. I'd call that a win.
NomadJim joined the channel
napperjabber joined the channel
NaOH joined the channel
Shariq has quit
racycle has quit
bigkevmcd has quit
abisson joined the channel
Raisins has quit
mattmakai has quit
kristallpirat has quit
kristallpirat joined the channel
zxq9
notanumber: The reason for the slowness was the same reason it didn't display anything. Each iteration was hitting the database an additional time (which can be enormous numbers of hits, like tens of thousands on large results of non-trivial data processing), *and* without a specific fetch for a value nothing would have been evaluated in the first place.
kristallpirat has quit
kristallpirat joined the channel
Raisins joined the channel
notanumber
Oh yeah, I'm fully aware of that. My philosophy is to to write it once, then profile and fix the slow bits. No sense spending time on something that's only run once every other month. In this case though, it was clearly broken. I would have had to fix it eventually anyway as this routine was seeing a lot of usage.
To much to do to little time.
Back2Basics joined the channel
baccenfutter has left the channel
P0w3r3d joined the channel
luke_66 joined the channel
luke_66
hi evryone
*everyone
bigkevmcd joined the channel
EyePulp has quit
dennis_m has quit
Scottyob
this might sound like a stupid question, but is it possible to create an empty query which doesn't return anything (so I can then later use |= with it?)
Scottyob: The closest thing would maybe be an empty Q object that you could |= to. But while query objects themselves behave similar to lists, they are not actually lists, so appending them doesn't work the way you're thinking.
Scottyob: If you extract query results as a list of models, however, you can then .append() or .extend() the list and do whatever you want.