#django

/

      • goldfish has quit
      • mucco_ joined the channel
      • moldy
      • renlo joined the channel
      • prsn: write a template tag then. but to be honest, i'd just edit the template, probably.
      • Ryanar
        If I want to link to this in reStructured Text how would I do it? https://docs.djangoproject.com/en/1.10/ref/requ...
      • this is what I tried: :class`~django.http.HttpRequest`'s :ref:`META<django.http.HttpRequest.META>`
      • chowmeined has quit
      • mucco has quit
      • chowmeined joined the channel
      • mucco__ joined the channel
      • Mikerhinos joined the channel
      • moldy
        Ryanar: link from where? from inside django's docs?
      • Ryanar
        yeah
      • the page has the following label .. _httprequest-attributes:
      • moldy
        Ryanar: i can never remember the details of the rst / sphinx syntax. i'd look up an equivalent that is already there and copy/paste/edit it :p
      • mucco_ has quit
      • chowmein__ has quit
      • chowmein__ joined the channel
      • Back2Basics has quit
      • detseg joined the channel
      • Technodrome has quit
      • Xorg joined the channel
      • chowmeined has quit
      • not_a_web_devbot has quit
      • chowmeined joined the channel
      • lborda joined the channel
      • chowmein__ has quit
      • apollo13
        mar77i: User.save wouldn't know if .password is already encrypted or not
      • tulioz joined the channel
      • fcoelho joined the channel
      • Ryanar
        got it, :class:`~django.http.HttpRequest.META`
      • renlo has quit
      • lborda has quit
      • surfnturf__ joined the channel
      • mYk joined the channel
      • mYk
        hello
      • let's say I have two unrelated models, each with an email field
      • I want to join these models,
      • can the ORM help me?
      • typically I'd like to select instances of one model, filtered by the existence of a related model matching some conditions
      • glassresistor joined the channel
      • I'm aware of the possible performance issues of such a join. just curious if there's a way to do it without dropping to raw SQL (which is a fine answer there)
      • moldy
        apollo13: fooling around... err... A/B testing shows that it's related to the django-cms placeholder cache :-/
      • Technodrome joined the channel
      • loic84 has quit
      • bouke has quit
      • tulioz has quit
      • mcspud
        mYk - Model1.objects.filter(email=Model2.objects.get(email=email))?
      • mar77i
        you can do that?
      • mYk
        well I don't think this is going to work very well
      • mar77i
        shouldn't it be email__in=...?
      • mYk
        yeah that answer made me realize I can do it with a subquery
      • moldy
        mYk: iirc you can't do a db-level join in that case
      • mYk
        s/I can/perhaps I can/
      • Model1.objects.filter(email__in=Model2.objects.filter(...).values_list('email', flat=True)) -- not sure that works, and if it does, it's going to fetch the list and pass it back to a second query
      • moldy
        mYk: something like that should work, yep
      • for a real join, you need raw sql, afaik
      • mYk
        yeah that's the conclusion I'm reaching as well
      • thanks for your help!
      • loic84 joined the channel
      • django417 has quit
      • lborda joined the channel
      • ironfroggy joined the channel
      • apollo13
        mYk: you might be able to drop .values_list, django should be smart enough to figure it out (tm)
      • tulioz joined the channel
      • mYk
        needs testing, then
      • apollo13
        at least if it is the pk, if not, you can drop flat at least
      • Impaloo joined the channel
      • so probably just .values('email') if email != pk
      • mYk
        I'm still at the thought experiment stage because I'm writing a spec
      • apollo13
        oh?
      • spec for what :)
      • mYk
        spamming
      • err
      • nagging users who requested a quote until they purchase a plan
      • hylje
        :^)
      • streblo has quit
      • mYk
        it's a bit complicated since they may have reached any stage of our 4-step subscription pipeline an arbitrary number of times, and each of these may trigger different emails, but you don't want to send *all* these emails
      • hence the not-entirely-trivial design
      • apollo13
        so you might be able to make use of union and intersection :D
      • ironfroggy has quit
      • HowardwLo joined the channel
      • streblo joined the channel
      • felixx joined the channel
      • surfnturf__ has quit
      • moldy
        apollo13: https://dpaste.de/8bmC do you happen to have any idea?
      • Xorg has quit
      • sheshkovsky joined the channel
      • pokEarl joined the channel
      • ironfroggy joined the channel
      • READ10 has quit
      • eperzhand joined the channel
      • offs3tzer0 joined the channel
      • mcspud
        mYk - you can use union
      • apollo13
        moldy: well, pickle works recursive, so you have to drill down through the response
      • woltman joined the channel
      • moldy: also check if response.request or so exists
      • mYk has left the channel
      • that said, I think pickling responses is buggy at best
      • moldy
        apollo13: hmm, ok, thanks
      • but the page cache relies on this, right?
      • apollo13
        moldy: basically do dir(value) and then if request is there do del response.request and see if it pickles
      • veduardo has quit
      • if yes the request is at fault :D
      • yeah
      • page cache pickles the http response, but we had a few errors like that in the past
      • imo the page cache should pickle body + headers, not the whole response
      • moldy: oh I was wrong, try if value._closable_objects.clear() and then dumping fixes it
      • renlo joined the channel
      • moldy
        apollo13: nope, same problem
      • apollo13: i should add that type(value) is <class 'rest_framework.response.Response'>, might well be related to that
      • apollo13
        stupid questio, but is the response already rendered?
      • oh, mhm
      • if that adds weird extra thingies, then for sure
      • moldy: you could run response.__getstate__ and see what comes out
      • Technodrome has quit
      • moldy
        stuff ;p
      • apollo13
        obviously, but copy that into an editor and search for lambda?
      • maybe throw through prettyprint?
      • moldy
        apollo13: yeah, good idea
      • eperzhand has quit
      • eperzhand joined the channel
      • eperzhand1 joined the channel
      • sheshkovsky
        hi, i want to know if i define explicitly in database router to route all read/writes to the 'default' db, and then use Mode.objects.using('another_db').all() , that will overrides the router and hits `another_db`?
      • mattmcc
        You don't even need a router for that. By default, reads & writes will already use the default DB.
      • melhiors joined the channel
      • SmileyChris joined the channel
      • sheshkovsky
        @mattmcc : yes, but i wanted to make sure no read/write goes to any other db by mistake
      • because have same models on both db s
      • eperzhand has quit
      • eperzhand1 has quit
      • i also needed router to prevent `another_db` from migration
      • username_ has quit
      • eperzhand joined the channel
      • retailify joined the channel
      • the_rat has quit
      • pannonia joined the channel
      • pannonia
        I can shell in and call_command a management command of mine, with the appropriate settings file, etc. Works great. When I try to do so on the command line, python manage.py my_command... I get all these weird import errors. Ive run out of ideas of things to consider.. Same settings file, same python, same virtualenv.
      • moldy
        pannonia: can you show us the errors?
      • tompaw joined the channel
      • sheshkovsky has quit
      • streblo has quit
      • pannonia
        ah thanks well it'd take a while to clean out sensitive stuff, but the errors are all ImportErrors. The management command imports a model that imports something else etc... Again works fine as django.core.management.call_command but wont work as straight python call...
      • I've given full path to .virtualenv/project/bin/python and full path to manage.py. Just running out of things to check
      • moldy
        without seeing any error, we don't have much basis for guesses
      • circular imports?
      • pannonia
        yeah. hm. ok well Ill spend some time recreating issue in simpler code I can share. Appreciate your taking a stab at it.
      • eperzhand has quit