#django

/

      • uestra joined the channel
      • uestra has quit
      • JZA joined the channel
      • lvns joined the channel
      • Stragler has quit
      • bsl10 joined the channel
      • pyface joined the channel
      • adamsilver joined the channel
      • adamsilver
        How can I say this in a better way: https://bpaste.net/show/7d352f6fbcc9 ... output: {'may': None, 'nov': None, 'apr': None, 'aug': 3, 'oct': None, 'jul': None, 'feb': None, 'sep': None, 'jan': None, 'jun': None, 'mar': None, 'dec': None}
      • pingveno
        adamsilver: So you're okay with hardcoding the dict?
      • MikiSoft
        cnk, airstrike: Event.objects.filter(id__in=Like.objects.filter(content_type=17, person=u).values_list('object_id', flat=True))
      • adamsilver
        pingveno: I don't mind if I get the months as numbers
      • MikiSoft
        it really was *that* simple
      • i have just 'converted' cnk raw sql query to django orm
      • reisio has quit
      • subho has quit
      • cnk
        except you are not guaranteed that Event is content type 17
      • MikiSoft
        yeah i'll change that
      • to this: ContentType.objects.get(model='event')
      • adamsilver has quit
      • amcorreia has quit
      • also i'm trying to figure out how to filter only object_id in queryset, because maybe it would be a performance hit since it unnecesarily queries other fields too
      • and i need only that field
      • royendgel joined the channel
      • and it performs the query twice
      • but i don't see the other way of doing it
      • GeorgeMCW_work has quit
      • therefore, cnk, it would be slower than using .raw()?
      • raijin has quit
      • jessamynsmith joined the channel
      • cnk
        you will have to try each and benchmark
      • wldcordeiro joined the channel
      • Synthead joined the channel
      • renlo has quit
      • jessamynsmith has quit
      • XofP has quit
      • MikiSoft
        raw(): 0.00012254714965820312 seconds
      • ORM: 0.01342463493347168 seconds
      • it's *much* faster
      • about 100 times
      • mcspud
        wow
      • Can you post both of the queries?
      • MikiSoft
      • mcspud
        My best bet is that most of that time is converting between Django ORM methods into SQL primitives, and not actually run time
      • MikiSoft
        this is the first function
      • and here's the second one: https://dpaste.de/Hnkw
      • mcspud
        MikiSoft - do `ContentType.objects.get(model='event').query`
      • See what django is actually generating
      • MikiSoft
        actually, there's no executed query to ContentType there
      • JZA has quit
      • because when starting the app CONTENT_TYPES constant is populated with needed data
      • mcspud
        You're compairing a reified string do a raw SQL statement, if you're doing it from the python shell this is the wrong way to do it
      • You need to DB to profile it for you
      • Also, you're arguing about 1/10th of one second, which is funny
      • MikiSoft
        i don't understand what you're saying?
      • what if 100 users decide to execute such query at the same time?
      • mcspud
        How are you timing the transactions?
      • MikiSoft
        or even more
      • i'm timing it like this
      • mcspud
        How are you timing the DB transactions?
      • MikiSoft
        start_time = time.time()
      • mcspud
        ok, thats wrong
      • MikiSoft
        model.objects.filter(pk__in=target.objects.filter(content_type=CONTENT_TYPES[model.__name__.lower()], person=person).values_list('object_id', flat=True))
      • print("--- %s seconds ---" % (time() - start_time))
      • JZA joined the channel
      • mcspud
        Yes, so you don't know what you're doing
      • MikiSoft
        why?
      • in the case of ORM it's executing the query *twice* so that's the reason why it's much slower
      • raijin joined the channel
      • in the case of .raw() it's executing it only once
      • but i don't know the other way of doing it in one query in ORM
      • jbitcm- has left the channel
      • jbitcm- joined the channel
      • maybe it can be made through .extra() command to be faster but i'm not enough experienced to make it
      • mcspud
        You're timing 2 things, you're timing the time it takes to convert chained method calls into SQL, and then the time to actually run the SQL
      • andyt_ joined the channel
      • type this instead: model.objects.filter(pk__in=target.objects.filter(content_type=CONTENT_TYPES[model.__name__.lower()], person=person).values_list('object_id', flat=True)).query
      • The .query flag will give the SQL you can use to time
      • andyt has quit
      • MikiSoft
        yeah but then it would give me the query which does the other half of the job
      • because it executes two queries
      • danpalmer has quit
      • jbitcm-
        hello
      • eperzhand joined the channel
      • did you see my las error https://dpaste.de/6TsA
      • i am new in django and im trrying to do the tutorial
      • this and if you se in line 7 of my code is not the same answer
      • OtherAllan
        you need the `__str__()` method in your question/poll models
      • jbitcm-: ^
      • make sure its the same as the tutorial `return self.question_text`
      • jessamynsmith joined the channel
      • MikiSoft
      • finally made it with extra(), now it returns QuerySet instead of RawQuerySet
      • boxbeatsy joined the channel
      • boxbeatsy
        hi all, i'm currently using python-memcached w/ my django app. i recently had a degradation problem which caused all memcached server requests to freeze, which resulted in 503 errors to my users (since the request took longer than 30s to process). what would be the best way to degrade gracefully in the future? i'd like for each memcached call to fail silently (or return None) if it takes longer than 0.1s.
      • amcorreia joined the channel
      • jbitcm-
      • cnk has quit
      • workbean joined the channel
      • andyt_ has quit
      • MikiSoft
        correction of the code from the last link i've posted above: https://dpaste.de/DSHp
      • Y04NN has quit
      • jbitcm-
        OtherAllan: do you know who is my problem naw?
      • bilal80 joined the channel
      • andyt joined the channel
      • masterteedy joined the channel
      • MikiSoft has quit
      • bx2 joined the channel
      • poz2k4444 has quit
      • bx2 has quit
      • coyotebm
        hey guys
      • anyone use django-openid package yet?
      • rnd_gen joined the channel
      • spsoni joined the channel
      • jessamynsmith has quit
      • zamro joined the channel
      • netheranthem has quit
      • sebastian-w has quit
      • jessamynsmith joined the channel
      • limbera
        i've been trying to find some good django assessment tests - does anyone have links to some free content?
      • what i mean is assessing someones knowledge of django, not writing test code
      • sebastian-w joined the channel
      • deltaskelta
        How would you go about calling an API in your views? Seems easy but I am drawing a blank...https://dpaste.de/FaNn#L7,8
      • hamub joined the channel
      • poz2k4444 joined the channel
      • jessamynsmith
        deltaskelta: um, usually you're either making an ajax request, using javascript, from the rendered view
      • or you're calling python code directly
      • what are you trying to do?
      • limbera
        deltaskelta: you can use requests to make an HTTP request to whatever service you need
      • if the service is large enough they may even had a python SDK you can use
      • stickperson joined the channel
      • jessamynsmith
        limbera: ah, you are calling someone else's api?
      • deltaskelta
        I want to call my DRF API from another view within my own project, and display the data along with custom forms and context...
      • limbera
        why not just call the function directly?
      • or abstract the logic into a function - and then have the API endpoint call that abastracted function
      • jessamynsmith
        right, so if you want to get data from your own, you should... what limbera said
      • limbera
        and your other function do the same thing
      • jessamynsmith
        you can call the serializer directly and get the data from it, if that's what you need
      • deltaskelta
        hmm ok I'll try to make sense of some of that and try it out in my code. Thanks
      • shangxiao joined the channel
      • zivester joined the channel
      • kyheo joined the channel
      • zamro has quit
      • religious has quit
      • zamro joined the channel
      • mcspud
        Hey, I've been through the docs and can't see it. If I mock something out, and I access to a Call object, how do I access the arguments that were passed to it? Like this: https://dpaste.de/TSOm
      • ADubhlaoich has quit
      • deltaskelta
        jessamynsmith: limbera: I am having some trouble calling the function directly like you were talking about. I know its right in front of me but I can't see how to do it.https://dpaste.de/Gn6H