wyoung: Can you try using .extra(tables=['UNNEST(periods, days, weeks, months, years) AS u'])?
But that probably won't help with the column definitions anyway.
I think you probably won't be able to write that using the ORM.
wyoung
:(
reficul31 has quit
schinckel
But, you could write a PG view that has that, and then put a model in front of that.
reficul31 joined the channel
wyoung
schinckel: isn't that hacky?
FunkyBob
not really
unmanaged model
helical joined the channel
ironfroggy has quit
ironfroggy joined the channel
schinckel
Then you'll just be able to treat it as a model class.
It's actually really neat.
FunkyBob
add a migation to create the view.... sorted.
wyoung
yeah, it seems nice in theory, I will need to do some experimenting
schinckel
I use that pattern a lot.
FunkyBob
in practice, it's been working for schinckel for years :)
schinckel
Also, I use a nice system for versioning the SQL views too.
strungout has quit
wyoung
It is just shifting where you use raw sql though.
FunkyBob
it lets the ORM treat the view like a table
wyoung
schinckel: how do you go with versioning models? :)
schinckel
<appname>/sql/<viewname>.view.000x.sql
strungout joined the channel
Oh, that's versioning the VIEW, rather than the model.
wyoung
right, is there a point versioning the sql when you don't version the model? they can be out of sync, especially if you have another migration that is doing something on a model when it is expected it to be a certain way,
ironfroggy has quit
milardovich joined the channel
schinckel
You write the VIEW so that it doesn't require any parameters, and let PG push the query parameters to your queryset, so there's no injection worries.
geewonder joined the channel
Yeah, Django will create migrations even for unmanaged models (they just don't do anything in the db)
wyoung
yeah I can express my UNNEST madness without requiring parameters. I just need to group on activity_id and period_unit
any way, bbl
schinckel
Then, you update the VIEW as necessary (and have the correct version loaded into the db within the same migration as the Model update operation is).
I have a custom migration operation that loads the correct version of the VIEW (based on the version number), so reverse migrations work too.
FunkyBob
app time, schinckel !
schinckel
The only place it breaks is if you try to re-order view columns, or change their type.
Yeah. One day.
Maybe I'm saving that one for a presentation... ;)
geewonder
I have a kind of conceptual database design question. I'm making a geospatial data visualization app. I have models representing various geographic subdivisions (zip codes, census tracts, etc.) Over time, I want to bring in lots of data sources that are reported on a per-region basis (e.g., income per capita). Should I just keep adding fields to the ZipCode model, or put each new data series on a separate table with a relation some
Nizumzen joined the channel
milardovich has quit
I'm kind of tempted to just put a JSONField called "data", and add keys over time. It's certainly easy. But it feels like it might be wrong. Any strong arguments against it?
adsworth_ joined the channel
the_rat joined the channel
adsworth has quit
hamub joined the channel
jhfisc has quit
the_rat has quit
bradfordli123 has quit
bradfordli123 joined the channel
splendor joined the channel
geewonder has quit
nry has quit
bradfordli123 has quit
mastizada joined the channel
laugh1ngpanda joined the channel
laugh1ngpanda has quit
woltman has quit
hamub has quit
Valduare
hmm
timkofu joined the channel
reficul31 has quit
adsworth_ has quit
Koterpillar joined the channel
retailify joined the channel
milardovich joined the channel
Nizumzen has quit
asadjb joined the channel
milardovich has quit
asadjb has quit
tsujin joined the channel
offs3tzer0 joined the channel
kyheo joined the channel
kyheo has quit
rpkilby joined the channel
milardovich joined the channel
milardovich has quit
Koterpillar has quit
offs3tzer0 joined the channel
hmm can I put variables in settings.py and call them in admin.py
mattmcc
Valduare: Yes, but what are you actually trying to do?
Valduare
figured it be better to save an api key in settings.py