#django

/

      • Leeds joined the channel
      • khimera joined the channel
      • thnee has quit
      • mpg300 joined the channel
      • kanja joined the channel
      • chachan has quit
      • kanja has quit
      • joshfinnie has quit
      • joshfinnie joined the channel
      • fmariluis joined the channel
      • dsb joined the channel
      • rolleiflex has quit
      • dsb
        So...I have a user model with two fields that specify that their default values are the result of a function. No big deal.
      • demet8 has quit
      • I have a management command which does NOTHING with that same function, and yet I am seeing it called, simply by having the default value present.
      • It is worth noting that the fields with the default values are a UserProfile field, and registered as such.
      • rolleiflex joined the channel
      • Any reason why calling ./manage.py myfunc would cause this function to be called in the UserProfile field?
      • Anyway to make it not do that? It's a little confusing.
      • gazumps has quit
      • superflit joined the channel
      • raininja has quit
      • keimlink has quit
      • tm8522010 has quit
      • It should only print "hi there"...no idea why the output of the other function (that is simply used to provide default value) is being shown.
      • eukreign joined the channel
      • gazumps joined the channel
      • backjlack has quit
      • Squarepy joined the channel
      • Shorter version of my question: does calling a command created for manage.py instantiate a User?
      • jfw
        no
      • your code is wrong
      • but it has nothing to do with django
      • dsb
        ok
      • mihasya has quit
      • jfw
        look at your class defintion
      • the fields in which you're setting a default
      • what are you setting the default *to*?
      • dsb
        part of the output of the function.
      • fosky joined the channel
      • the function returns a pair...something like (5,6)
      • one field gets the first value, the second the other.
      • What I don't get is why the management command, which right now only prints a message, would instantiate User (or UserProfile)
      • jfw
        okay, so now you've set the default for every single instance to (5,6)
      • you sure that's what you want?
      • seagreen has quit
      • dsb
        Not for every instance...just new ones, right?
      • the function will increment the values to other pairs that are not used.
      • jfw
        nope. it only ever gets run once, so it's going to be the default for every instance
      • dsb
        really?
      • ptomblin joined the channel
      • jfw
        sure. try it with a simple example
      • class A:
      • EyePulp joined the channel
      • fission6 joined the channel
      • hmm, okay, not going to write code in the channel :)
      • dsb
        so the function only gets evaluated at start time? Once. Not at instantiation?
      • Interesting.
      • SmileyChris
        correct, that's how python works
      • dsb
        I was about to say I've done something similar before...but thinking about it...I had the function get called in a form, not the model.
      • jfw
        you got it :)
      • but again, nothing to do with django. you *can* do what you want in a model
      • you just have to pass a *function* instead of the the *output* from a function
      • SmileyChris
        for example, default=lambda: get_next_vpn_ip_pair()[1]
      • node-less has quit
      • dsb
        heh...so, take away the two fields thing... could I have also just said default=get_next_vpn_ip_pair, w/o the parens. Or is lambda req'd to do this?
      • SmileyChris
        no, just passing the function would be enough
      • dsb
        The More You Know(tm)
      • lemme go try!
      • mattmcc
        Lambda isn't required for anything in Python.
      • node-less joined the channel
      • dsb
        Though...so I was seeing that function called, since django does some initialization when running the command right? Including instantiating a User of some kind?
      • raininja joined the channel
      • SmileyChris
        it's not done at instanciation
      • it's done when building the class
      • jfw
        that's why you can do things like generate classes on the fly
      • jimmyalcala has quit
      • dirn has quit
      • fission6
        mattmcc: you around
      • mattmcc
        More or less.
      • kanja joined the channel
      • mihasya joined the channel
      • gerard0 has quit
      • dsb
        jfw, SmileyChris...dead on! Thank you for the assist!
      • ben174 has quit
      • jasongonzales joined the channel
      • estebistec joined the channel
      • jasongonzales
        hey there I need some help with this problem
      • vassy has quit
      • jfw
        no prob! cheers
      • __machine joined the channel
      • dirn joined the channel
      • luyikei__ joined the channel
      • F1skr has quit
      • mihasya has quit
      • joshfinnie has quit
      • aleray joined the channel
      • newzen has quit
      • aleray
        hi, I have a big template that makes heavy uses of the regroup template tag. I suspect this is why it is so slow. Is there any alternative to it? (i'm thinking on the queryset/database level)
      • khimera has quit
      • kanja has quit
      • hyperair has quit
      • gremly has quit
      • jasongonzales
        hey, can anyone help with this? http://dpaste.org/Zp6wS/#L trying to get the view to look like what I describe at the bottom
      • raininja has quit
      • codeme
        aleray: do you have a site with big template ?
      • seagreen joined the channel
      • jfw
        jasongonzales: you haven't said what the problem is
      • aleray
        codeme, not sur to understand your question... My english is kind of broken. I meant a large template
      • jfw
        aleray: move your logic to your view or model
      • aleray
        jfw, I could use itertool or something like this but will it be faster?
      • jfw
        i couldn't possibly say. it depends on many things
      • aleray
        I have many regroup tag nested...
      • jfw
        that's bad
      • even if not for speed (which it's probably pretty bad for) that's going to be a pain to maintain
      • anytime you find yourself doing anything complicated or nesting more than a level or two deep, move the logic to your view or model
      • amizya has quit
      • aleray
        jfw, here is a snippet http://dpaste.com/1077213/
      • (includes also use regroup tags :()
      • hwrd|work has quit
      • jfw, an other one http://dpaste.com/1077215/ which should give you a pretty good overview of the whole
      • danfairs has quit
      • or more specifically: how can I make less expense such a statement? `{% regroup o.foo|dictsort:"o.foo" by o.foo as oo %}`
      • bahodir joined the channel
      • __machine
        is it possible to use startproject —template and specify that files *without* an extension should be rendered? by default only .py files are rendered... i can add additional extensions with -e but how do i add the lack of an extension? (Makefile in docs dir, created by sphinx-quickstart) ?
      • foundatron joined the channel
      • schnoodles joined the channel
      • k_sze[work] joined the channel
      • mattmcc
        __machine: That's probably bug report worthy, because I bet it's not supported..
      • And it obviously should be, since we unix people aren't supposed to care about file extensions.
      • manfre has quit
      • __machine
        thanks i will open a ticket
      • fmariluis has quit
      • aberrant joined the channel
      • looks like it's already done... with a —name argument... yay...
      • aleray
        jfw: any direction to suggest?
      • lduros
        when you do loaddata fixtures/initial_fixtures.json
      • does it actually overwrite the database?
      • or does it add new entries if it's an existing db?
      • bahodir has quit
      • OldCoder_ has quit
      • oxbits joined the channel
      • dirn has quit
      • EyePulp has quit
      • octarine joined the channel
      • hwrd|work joined the channel
      • ArtVandalae has quit
      • hmm looks like it wipes out the db, because there's no duplicate entries while there should have been after i ran loaddate