#django

/

      • medj
        No, it should never change.
      • jdunck joined the channel
      • protokol has quit
      • refu joined the channel
      • refu
        Hello
      • How are you?
      • I have a question
      • I need compare date in django
      • but i don't know how I can do it
      • I need filter object with a month difference of today
      • m0n5t3r has quit
      • how I can do it?
      • urth
      • refu
        oh! Thanksyou! urth
      • FunkyBob
        refu: are you using a git checkout of Django?
      • if not, change 'dev' in that URL to the version you'r using... e.g. 1.4
      • refu
        mmm I am using 1.4
      • because I am installed Archlinux as principal OS
      • cramm joined the channel
      • this OS always have the last version of almost softs
      • amccloud has quit
      • smill
        funkybob: just the man i was looking for, you always seem to know what you're talking about, may i ask you a legacy db question?
      • FunkyBob
        refu: wow, you're using a distro provided package? brave
      • amccloud joined the channel
      • smill: you overestimate my skills :)
      • ask away
      • refu
        mmm, i dont know, I install django for aur xD
      • Boydy joined the channel
      • medj
        OK, thanks!
      • medj has quit
      • FunkyBob
        refu: learn to love virtualenv :) then always pip install
      • smill
        funkybob: ok well basically i have a legacy db that has an items and sections table, then a third table called Section_Items that just has the section id and item ids to link them together, because each item can be in multiple sections
      • funkybob: relevant paste here http://dpaste.com/899084/
      • FunkyBob
        smill: so, it's a Many-to-many "through" table?
      • robvdl joined the channel
      • smill
        funkybob: that was my general impression but i can't for the life of me figure out how to set it up! i have read about manytomany things but it seems to be adding functionality and i'd have to manually go through and redo the "links" between the tables
      • skandocious joined the channel
      • refu
        ahhh yes! I listen about virtualenv
      • skandocious
        if i execute Person.objects.get(id=1) 10 times in a function, does it hit the DB 10 times?
      • or are the latter 9 times pulled from a cache?
      • FunkyBob
        smill: create a model for Section_Items, and set it as the 'through on a ManyToMany field on one of the models
      • skandocious: I'd hope it would hit it 10 times
      • skandocious
        FunkyBob: thats what i figured
      • bubu___ joined the channel
      • FunkyBob: i'm doing a CSV dump function that resolves FK's before dumping
      • FunkyBob: and its resolving the same keys over and over...
      • bulkan has quit
      • FunkyBob: takes FOREVER
      • FunkyBob
        skandocious: yeah, that's why we made cache dicts...
      • skandocious
        FunkyBob: ooo whats what?!
      • FunkyBob
      • you use one of those
      • skandocious
        I'm familiar with defaultdicts
      • FunkyBob
        and build it so accessing a missing key will get the object from the DB, _and_ store it in itself
      • then you have a transparently caching dict of objects :)
      • skandocious
        FunkyBob: ah well i already did something like that
      • superdmp has quit
      • hang on
      • FunkyBob
        you MUST remember to have your __missing__ method store the value back into itself
      • sgambino joined the channel
      • skandocious
      • FunkyBob: memoize :)
      • FunkyBob
        that's another option, sure
      • skandocious
        FunkyBob: same idea, right?
      • FunkyBob
        but more flexible, yeah... memoize can take more arguments
      • skandocious
        FunkyBob: yeah
      • cibermarsam has quit
      • FunkyBob
        of course, you'll probably find select_related would save you all [most of] those hits anyway
      • skandocious
        FunkyBob: will it?
      • won't that resolve all the foreign keys in 1 swoop?
      • FunkyBob
        it'll do it as part of the initial query
      • skandocious
        i don't necessarily want to resolve all of them… that might be expensive…
      • chrisramon joined the channel
      • FunkyBob
        then tell it which ones you do know you want to reolve
      • skandocious
        plus if 2 tuples point to the same FK, that FK will get resolved twice
      • FunkyBob
        resolve
      • yes, but it's still JUST ONE QUERY
      • skandocious
        tuple1.select_related() // resolves FK
      • smill
        funkybob: I tried this http://dpaste.com/899096/ note the contained_items in the Sections model. it doesn't work tho, I hate to ask you to spell this out for me but I have been screwing with it for a couple hours and I can't get it
      • skandocious
        tuple2.select_related() // resolves same FK again
      • mgrouchy joined the channel
      • FunkyBob
        skandocious: huh?
      • skandocious: do it as part of your QuerySet
      • I have no idea what tuple1 and tuple2 are supposed to be there
      • skandocious
        FunkyBob: ohhh the original objects.all() call
      • by tuple i mean row/model-object
      • FunkyBob: but yeah i get what you're saying now
      • FunkyBob
        MyModel.objects.select_related() ...
      • skandocious
        FunkyBob: gotcha
      • FunkyBob
        smill: I see the problem.. you haven't expressed the relations
      • rolleiflex has quit
      • smill
        funkybob: do I need to put in ForeignKey things?
      • FunkyBob
      • fortunately, your schema follows django's field naming :)
      • also, no need to define an Integer primary key whose name is 'id'
      • though you may want to ensure it's using .... whatever implementation of PK sequence generation your DBMS uses
      • vbabiy joined the channel
      • atula joined the channel
      • bvlaar has quit
      • bvlaar joined the channel
      • smill
        funkybob: ok, thanks, that makes sense. however i'm still getting the same error "'Sections" object has no attribute 'contained_items_set'"
      • chrismed has quit
      • repsaj has quit
      • robbyoconnor has quit
      • FunkyBob
        that's because it doesn't
      • you called the m2m "contained_items"
      • cramm has quit
      • the '_set' suffix is only used for _auto-generated_ reverse references
      • so, for your case, Items will have a sections_set property
      • plabo joined the channel
      • Sharebear has quit
      • odarbelaeze joined the channel
      • Amitash
        I currently have a view which returns: return render_to_response('login.html',{'state':state, 'username':username}). I have created a csrf_token in this view and I need render_to_response to return this as well.. How do I change the return statement?
      • Technodrome has left the channel
      • FunkyBob
        Amitash: firstly, you will finde life easier [especially hwne using csrf] to use render, not render_to_response
      • smill
        funkybob: I tried section.itemlist = Items.sections_set.all() and it says "'ManyRelatedObjectsDescriptor' object has no attribute 'all'" :(
      • odarbelaeze
        Hi there, I'm using django boilerplate, in a medium sized project, its time to start tryals with DEBUG = False, but I'm getting a mysterious 500 error each time I set the flag to false
      • FunkyBob
        Amitash: the reason is render() will use a RequestContext
      • Amitash: [and there's less typing :)]
      • odarbelaeze: have you written a 404 template?
      • odarbelaeze
        I there any way to figure out what is happening, the only thing I'm getting is "GET / HTTP/1.1" 500 27?
      • Amitash
        FunkyBob: I keep getting the csrf token error.. I am trying step 3, sub step 2 of the django docs: https://docs.djangoproject.com/en/dev/ref/contr...
      • md4d joined the channel
      • FunkyBob
        Amitash: Are you using a git checkout of Django?
      • vbabiy has quit
      • polishnorbi has quit
      • Amitash: I'm betting you're not...
      • odarbelaeze
        FunkyBob: yep, or I'm too fool trying to set the flag to false with the development server?
      • Amitash
        FunkyBob: Nope
      • sivy has quit
      • FunkyBob
        Amitash: then stop using the dev docs...
      • Amitash: change 'dev' in that url to '1.4'
      • odarbelaeze: no, you're not
      • Amitash
        FunkyBob: No difference in the docs :)
      • workkevin joined the channel
      • FunkyBob
        Amitash: no, but there could have been
      • Amitash
        FunkyBob: So should I use the HttpResponse instead of render_to_response?
      • audreyr joined the channel
      • FunkyBob
        Amitash: meanshilw... you need to pass the csrf token in the context so you can use it
      • Amitash: WTF? where did anyone suggest that?
      • render_to_resposne creates a HttpResponse For you
      • Amitash
        FunkyBob: Sorry.. I have only used Httpresponse before.. Am very new to django..
      • FunkyBob
        Amitash: and you've done the tutorial?
      • the 4-part one in the docs?
      • FSCV has quit
      • Amitash
        FunkyBob: I was following another book actually..
      • aclark
        /////////////////////////////////////////////////////////////////////w 3
      • md4d has quit
      • grrr
      • sorry