#django

/

      • amcorreia
        but even I using """ I need escape ?
      • FunkyBob
        ask the validator, mate
      • toothe
        The-Kid: what's wrong is that I didn't read the docuemntation prior to coming here and asking a question.
      • FunkyBob
        toothe: it's a bad habit we'll break you of eventually :)
      • The-Kid
        toothe: It happens to everyone. In some cases you may have read over it but missed something as well.
      • FunkyBob: But what if I don't want to look for the answers to my questions
      • FunkyBob
        ooh... is that a koan?
      • aardbolreiziger has quit
      • toothe
        this is a nice page though, I mustsay.
      • The-Kid
        FunkyBob: I don't follow
      • toothe
        btw, it took me like 4-5 weeks to even understand WTF was going on with django.
      • The-Kid
        toothe: Django is a large project and can take a bit of time to get the hang of
      • DLSteve joined the channel
      • FunkyBob
        toothe: I've given you the "the core of django" cycle description, right?
      • The-Kid
        toothe: Good choice though on moving to class based views.
      • FunkyBob
        The-Kid: you know they're slower, right? :)
      • ironfroggy joined the channel
      • The-Kid
        FunkyBob: I'm aware
      • FunkyBob
        :P
      • garrypolley joined the channel
      • The-Kid
        FunkyBob: Creating an object is more work then a function
      • FunkyBob
        than
      • also there's all the method calls, creating call contexts, etc.
      • The-Kid
        FunkyBob: I find them easier to read then function views though and that makes up for the extra overhead
      • FunkyBob
        _than_
      • then is a temporal term, like when
      • than is a comparative term
      • The-Kid
        FunkyBob: Thank you. I'm going to continue to mess that up btw. I will try not to though.
      • My spelling is not very good :(
      • FunkyBob
        well, I hope the then/when mnemonic will help
      • The-Kid
        FunkyBob: It likely will. I hope it does
      • garrypolley has quit
      • FunkyBob
        I should write a collection of them that I've learned/acquired/developed
      • The-Kid
        you should
      • ironfroggy joined the channel
      • I'm good with the you, your, you're
      • Debnet has quit
      • and a lot
      • FunkyBob
        your, you're, yore ?
      • their, there, they're?
      • just remember 're is abbreviation of "are"
      • then there's "here / there"
      • The-Kid
        I'm aware
      • ejb has quit
      • FunkyBob: so about that page of tricks ?
      • FunkyBob
        heh
      • mingrammer joined the channel
      • lolidunno
        I have an item list model with a price field that gets incremented and decremented when users add or remove items
      • what's the best way to handle scoundrels that try to overflow the max digits
      • I was thinking of just setting the field to the max value if it exceeds the max value in an overridden save method
      • Cavedude has quit
      • okimoyo
        If I'm using a model form to display a ForeignKey to a list of user accounts, is there a way to filter for accounts in some group?
      • mingrammer has quit
      • Cavedude joined the channel
      • FunkyBob
        lolidunno: your DBMS should limit that ... so do the operation in a transaction and catch the error
      • okimoyo: specify the queryset for the field?
      • okimoyo
        FunkyBob: Yes, that would do it....?
      • lolidunno
        ah, so just a try/catch in the view then
      • haber joined the channel
      • FunkyBob
        okimoyo: if you're not declaring the field explicitly, do it in a custom form __init__ self.fields['myfield'].queryset = ....
      • The-Kid
        I'm thinking about making a django backed html5 game
      • FunkyBob
        ok
      • okimoyo
        FunkyBob: Do you have to call super if you override __init__ like that?
      • FunkyBob
        okimoyo: yes
      • okimoyo: call it before you do your work
      • Doerno joined the channel
      • LiamM joined the channel
      • Doerno
        hi.How should I get the model name in overriden admin change template?
      • ironfroggy joined the channel
      • ironfroggy joined the channel
      • squeaky-clean has quit
      • akki has quit
      • brizz
        Account.objects.all()[0].postcontent.all()[0].content_index is a Integer field, when trying to modify the value of it, doesnt seem to save (stays 0) is it because of how im accessing the field?
      • ironfroggy joined the channel
      • FunkyBob
        brizz: wow, what an expensive operation
      • brizz: how are you accessing the field? what re you doing, _exactly_, when you try to update it?
      • use dpaste.de to show code
      • brizz
        trying to update from acc model in shell
      • FunkyBob
        show code
      • brizz
        i am able to edit in admin and it saves..
      • ironfroggy_ joined the channel
      • FunkyBob
        SHOW THE CODE
      • brizz
        Account.objects.all()[0].postcontent.all()[0].content_index = 3
      • account.objects.all()[0].postcontent.all()[0].save()
      • FunkyBob
        so there's your problem
      • brizz
        err Account.objects.all()[0].postcontent.all()[0].save()
      • FunkyBob
        you're getting an instance, and changing its value.... then getting a _second_ instance, and saving it
      • brizz
        and also tried to save acc object after doing postcontent
      • FunkyBob
        all up doing _4_ database reads
      • brizz
        lol k
      • FunkyBob
        one for account[0], one for postcontent[0]... then the same queries again..
      • and since there's no ordering... you have no idea which account of postcontent you get any time
      • [unless you have ordering on the model meta]
      • brizz
        so what i want to do... is 'postcontent' is apart of a tumblr account
      • an 'account' is one tumblr account
      • FunkyBob
        ever thought of holding onto the value you get? x = Account.objects.all()[0].postcontent.all()[0] ; x.content_index = 3 ; x.save()
      • eperzhand has quit
      • brizz
      • well i was doing ...not in shell
      • FunkyBob
        please read the topic... don't use pastebin, use dpaste.de
      • it doesn't matter _where_ you were doing it
      • brizz
        accounts = Accounts.objects.all(), then for acc in accounts: .... acc.postcontent.all()[0].content_index += 3
      • acc.save()
      • and that wasn't working, so then tried in shell
      • GeorgeJipa has quit
      • --point being i was getting at what you said, holding onto the value you get...wouldnt 'acc' be like xin above
      • jessamynsmith has quit
      • FunkyBob
        again
      • you're slicing a queryset.... INSTEAD OF HOLDING ONTO THE OBJECT YOU WANT
      • no... it would be the postcontent...
      • querysets are not lists
      • GeorgeJipa joined the channel
      • so you get a random postcontent... update it.. then get _another_ random one.. and save that, not the one you edited
      • post = acc.postcontent.first(); if post: post.content_index += 3 ; post.save()
      • brizz
        ahh i thought querysets were lists pointing to the objects
      • they arent?
      • FunkyBob
        no
      • very not
      • when you do [0] on it... it does another DB hit
      • also... since you're not using order_by ... it's likely you get a different one each time
      • domino14 joined the channel
      • domino14
        hey guys
      • FunkyBob
        (unless, as I said before, you have Meta.ordering defined on the model)
      • brizz
        yea im newb to relational dbs...no formal education or anything, messed w/php/mysql years ago. started learning django because i wanted the orm
      • domino14
        i get a RuntimeError in DEBUG mode when i try to PUT to a url that doesn't have a slash appended
      • because Django tries to append a slash and then complains that PUT data wouldn't go through
      • cnk has quit
      • however this works fine on prod -- why? how come PUT data went through on a redirect?
      • FunkyBob
        domino14: I'd more look at why you're generating incorrect urls
      • domino14
        Backbone is just generating these URLs that looks like /api/resource/35 or whatever
      • FunkyBob
        if y ou're using reverse / {% url %} properly... this problem won't happen
      • domino14
        without the trailing slash
      • FunkyBob
        then fix backbone
      • domino14
        all right
      • why is the PUT data going through on a redirect?
      • when django tells you that it can't do that
      • `Django can't redirect to the slash URL while maintaining %(method)s data.`
      • but this works on prod
      • FunkyBob
        domino14: no idea what's going on in prod
      • this is a long standing issue with redirect in http
      • [which I believe is actually fixed in all modern browsers]
      • domino14
        so modern browsers have no problem with correctly maintaining PUT/POST data on a redirect?
      • FunkyBob
        when the right redirect is used, they shouldn't
      • this is why there are [now] 3 redirect types
      • domino14
        this was on a 301 and data passed through ok
      • FunkyBob
      • Leeds joined the channel
      • MarkusH
      • FunkyBob
        MarkusH: !
      • how's your head?