#django

/

      • PKKid
        houman, then format the date correctly..
      • houman
        considering i18n, i would have to pick date.year, date.month etc myself and form a string like that myself right?
      • PKKid
        jrief_, I would do that as 2 queries.
      • jrwren, I woudl do that as 2 queries..
      • yea.. right person that time. :)
      • tie joined the channel
      • rsmol joined the channel
      • jrwren
        how would I do it as 2? its currently a nasty select n+1.
      • rsmol
        Hi, I have a url /report/html which renders nice report, but when I try to save this, it defaults to 'html', can I override this?
      • jrwren
        afaik, i cannot do it as 2 because that inner select in teh where clause references the outer t1.id
      • tmitchell has quit
      • activus1
        Z_A_M: what does this line do: p = get_object_or_404(PN, pk=policy_id)
      • rje has quit
      • Z_A_M
        activus1: It looks for a 'PN
      • drp
      • it looks for a 'PN' object with a primary key of = policy_id
      • if it doesn't exist it throws a 404 page
      • jita has quit
      • activus1
        Z_A_M: thanks
      • scooz has quit
      • Z_A_M
        activus1: yup! A lot of that stuff is in the django docs btw.
      • jsoa has quit
      • PKKid
        jrwren, ...
      • max_timestamp_id = t1.objects.order_by('-timestamp')[0].id
      • results = t1.objects.select_related('t2').filter(id=max_timestamp_id)
      • rje joined the channel
      • jrwren
        PKKid: that is not the same.
      • PKKid
        how i that not the same?
      • you eman if more than 1 object has the max timestamp?
      • mean*
      • You could do this if you expect more than 1 object to share the max_timestamp
      • max_timestamp = t1.objects.order_by('-timestamp')[0].timestamp
      • results = t1.objects.select_related('t2').filter(timestamp=max_timestamp)
      • novation
        is it possible to add/remove modelAdmin's inlines ?
      • I want to exclde some inlines if they are unnessecary (already filled in)
      • jrwren
        there isn't a single max_timestamp_id, there is a max for each t1
      • aleksm joined the channel
      • PKKid
        jrwren, I think I understand.. 2 sec
      • jrwren
        t1 is one to many t2.
      • rsmol has left the channel
      • kinabalu has quit
      • jadel has quit
      • m0no has quit
      • bryguy joined the channel
      • m0no joined the channel
      • jcarbaugh has quit
      • F1skr joined the channel
      • pyxorg has quit
      • atula joined the channel
      • void has quit
      • PKKid
        jrwren, How many objects do you expect t1, t2 to have?
      • void joined the channel
      • jrwren
        ~5k
      • and then anywhere from 1 to dozens on teh many size to t2
      • jita joined the channel
      • exit2
        is there anything I can do to automatically fill in a field of a model from models.py? I know I can do default='Whatever', but that doesn't actually fill the field in
      • PKKid
        jrwren, Also, I believe the ORM cannot do that query, at least not without storing a list of max_ids and using the __in filter.. which is a bit icky.
      • sligodave joined the channel
      • jcarbaugh joined the channel
      • jrwren
        i'm thinking about .extra(where=['???timestamp=(select max(t3.timestampe) from ??? as t3 where t3.???= ??? )']
      • but I don't know how I can fill in the table and field names from orm in the extra where
      • TopRamen has quit
      • i guess I can just hardcode, but I'd need to know the table alias name used if any... I guess django.db.connection.queries shows me there is no such alias
      • activus1
        Z_A_M: how do I return just plain text to the screen so I can see what was passed in ?
      • aaroncm has quit
      • aezell has quit
      • nickmeharry has quit
      • gremly has quit
      • PKKid
        jrwren, I wouldn't dig too deep into the ORM internals to write this. A raw query seems much more readable/maintainable imo.
      • gremly joined the channel
      • gerard0 joined the channel
      • nickmeharry joined the channel
      • jroll has quit
      • cewing|afk is now known as cewing
      • fmcgeough has quit
      • activus1
        return HttpResponse('POST')
      • got it
      • jrwren
        PKKid: thank you for your help
      • PKKid
        jrwren, Also note: this seems like a slow query either way. It might be worth flagging the max_timestamp rows when new rows are added. That would make this query blazing fast, easier to read (at the cost of slower writes to the DB)
      • sayan joined the channel
      • jrwren
        the select n+1 is insanely slow.
      • yassine has quit
      • the subquery is very fast.
      • Alws0nth3rn joined the channel
      • yassine joined the channel
      • novation has quit
      • PKKid
        if the rows were flagged, then you could do something simple like "SELECT * FROM t1 WHERE t1.max_flag"
      • jroll joined the channel
      • Shariq has quit
      • it also seems like this could be re-written using GROUP BY. Unless im missing something..
      • jrwren
        i thought group by at first too, but couldn't figure how to write it, so I ended up with this WHERE subquery
      • good point on the max_flag, we'd have to maintain it, but should simplify things.
      • Alws0nth3rn has quit
      • jonathanchu has quit
      • PKKid
        jrwren, I think this is a similar query, using GROUP BY and HAVING: https://gist.github.com/3540307
      • filer=t1, auser=t2 in your example
      • j2lab joined the channel
      • jo` has quit
      • jrwren, And here is a blogpost showing that the ORM somewhat supports HAVING: http://eflorenzano.com/blog/2008/11/06/secrets-...
      • quake_guy has quit
      • jrwren
        close, but no, that query isn't the same.
      • __love__ has quit
      • novation joined the channel
      • chrisjones joined the channel
      • if it were groupby,I'd only want to groupby t2.id (kinda like turning that one to many into a one to one based on max(timestamp) )
      • liefy joined the channel
      • but if I groupby t2.id only, sql errors that t1.id must appear in group by since it was in the aggregate
      • sayan has quit
      • maybe a group by and a join
      • hansy has quit
      • yes.
      • i must have first translated that gist incorrectly. I think I see now.
      • jita has quit
      • I should be able to follow that post and get it to work.
      • dmg412 joined the channel
      • hrm, or not.
      • andrewjsledge has quit
      • the group by on t1 works, but once I join t2 it does not.
      • jdo_dk has quit
      • PKKid
        hmm
      • im curious now.. :)
      • dmg412
        Starting with django 1.4, I am getting an issue where I am getting apache processes hanging forever. They seem to be stuck trying to get a lock in the _remove_receiver method (from the mod_wsgi stack traces). Has anyone come across anything similar to this? We can reproduce the issue in 1.4 but not using 1.3. http://pastebin.com/iPe0HjRv
      • Adys_ joined the channel
      • scooz joined the channel
      • chrisstreeter joined the channel
      • Adys has quit
      • jj0hns0n has quit
      • jj0hns0n joined the channel
      • randil joined the channel
      • radez has quit
      • andym has quit
      • PKKid
        jrwren, Still here..
      • ?
      • jita joined the channel
      • cyborg-one joined the channel
      • mlavin has quit
      • jonathanchu joined the channel
      • jita has quit
      • Or1on joined the channel
      • kilae has quit
      • jrwren
        PKKid: I'm going with extra(where=...
      • and the subquery.
      • i couldn't get a groupby having working.
      • marcosmoyano has quit
      • i could probably do it with 2 queries, the first being groupby and then the second being the old way with an additional IN but that IN value would have the 5000 values, not what I want.
      • PKKid
        jrwren, is it working?
      • jrwren
        looks like it.
      • goldfish_ has quit
      • i still need to profile the big picture, but this piece is great.
      • PKKid
        jrwren, Yea, that IN value thing would suck. :)