#django

/

      • schinckel
        wyoung: Oh, how did you get on with your stuff?
      • wyoung
        schinckel: I would still like your assistance if you are available :)
      • kyern has quit
      • Valduare
        you guys ready for my question of the night? :P
      • FunkyBob
        just the guys, mind...
      • wyoung
        Valduare: s/guys/djangonites/
      • schinckel
        wyoung: I might be lightly available now: writing and running tests, so...
      • wyoung
        :D
      • lastmanstanding joined the channel
      • schinckel: did you see the SQL query I was trying to create into an ORM expression? or should I send you the dpaste link again?
      • schinckel
        That was the UNNEST() stuff?
      • Valduare
        I have a model with a manytomany field, in my views I have the queryset and its returning the id’s of the manytomany field items.
      • wyoung
        yeah, UNNEST in FROM
      • Valduare
        how can I get the names instead of ids
      • wyoung
        schinckel: when used with group and aggregate it works quite sanely
      • FunkyBob
        Valduare: dpaste your models and your query code
      • wyoung
        group = group by
      • kyern joined the channel
      • reficul31 joined the channel
      • schinckel
        Maybe you'd better dpaste the query again.
      • AnInstanceOfMe has quit
      • Valduare
        objs = Message.objects.all().order_by('?')[0] im pulling a random record.
      • FunkyBob
        Valduare: and how are you getting the ids?
      • also, don't forget the handy first() method on queryset
      • obj.m2mfield.values_list('name', flat=True) <-- gets just a list of values from the name field
      • Valduare
        there’s so many options in django :) ty reading up on m2mfield and .values_list now
      • FunkyBob
        m2mfield was my guess are your many-to-many field name
      • because you refused to dpaste your models
      • Valduare
        oh i thought that was a special class heh
      • ok that works, ty values_list is what I was looking for
      • robvdl has quit
      • SmileyChris has quit
      • tulioz joined the channel
      • OtherAllan has quit
      • wyoung
        schinckel: will do!
      • not_a_web_devbot joined the channel
      • ironfroggy joined the channel
      • ellmetha has quit
      • shangxiao joined the channel
      • not_a_web_devbot has quit
      • ironfroggy has quit
      • ironfroggy joined the channel
      • heluca joined the channel
      • lastmanstanding has left the channel
      • eMyller has quit
      • FreedomFighter has quit
      • schinckel
        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
      • tdy has quit
      • tdy joined the channel
      • ah from django.conf import settings
      • this is what i was looking for
      • tdy has quit
      • rpkilby has quit
      • asadjb joined the channel
      • jarshwah_ has quit
      • jessamynsmith has quit
      • asadjb has quit
      • offs3tzer0 has quit
      • offs3tzer0 joined the channel
      • [0xAA] joined the channel
      • Nizumzen joined the channel
      • greg_f joined the channel
      • tulioz has quit
      • l0ser joined the channel