These are chat archives for django/django

Nov 2016
J. Dalton Childers
Nov 24 2016 01:45

I was able to get this working a count working like this:

def get_context_data(self, **kwargs):
        # Assign PK to Study ID for tweet
        study_id = self.kwargs['pk']
        # Call the base implementation first to get a context
        context = super(StudyDetailView, self).get_context_data(**kwargs)
        # Add in a QuerySet of tweets matching current study id
        context['total_tweets'] = Tweet.objects.filter(study=study_id).count()
        return context

Although this works it takes 2,000 ms to run the query using a postgres database. Does anyone know how I could increase the performance of this query and decrease the overall time it takes to do the count?

J. Dalton Childers
Nov 24 2016 02:16
It’s counting 1.7 million tweets.
Mark Heppner
Nov 24 2016 05:04
@jdaltonchilders i think you're joining on a non-indexed key. try setting and make a new migration. you'd probably also want to make it unique=True too, but honestly it would be better to make it a foreign key to ensure the constraint at the database level. what issues were you running into with that approach? also, if you use posgrest 9.6, they have multiprocessed workers that massively help with scans and joins.
J. Dalton Childers
Nov 24 2016 05:09

@mheppner I am currently using postgres 9.6. We were having issue with the package we’re using for the table partitioning. The issue is site here on github: maxtepkeev/architect#25

We also noticed, if we ever did get the partitioning working. If a tweet was to be reassigned to another table then :boom: the table would flip out and crash.

I updated the to be index so hopefully this will help some. The issue with setting it to unique is we’re doing the partitioning based on the study id and querying the tweets table based on the study id.
@architect.install('partition', type='range', subtype='integer', constraint='1', column='study’) This is doing the partitioning
J. Dalton Childers
Nov 24 2016 06:36
I followed this links (refer to sections E. and E. and; and I was able to resolve the issue some.
Miracle Ayodele
Nov 24 2016 07:47
A big thank you to @mheppner @RadoRado and @megapctr for your contributions and help concerning register and login challenges. I have finally cracked it, your contributions really helped. Thanks
Andrew Backer
Nov 24 2016 09:39
I need a recommendation on a good oauth package (primarily linkedin/google) that plays nice with JWT, local login, and per-user tokens or generic api keys. django-allauth seems interesting, but I am curoius what folks have had the most experience or best luck with
Mwai Karimi
Nov 24 2016 10:09
Morning lads! Has anyone here used Solr with django & haystack? If so, how can i go about this | Solr responded with an error (HTTP 400): [Reason: ERROR: [] unknown field 'django_id']
agus makmun
Nov 24 2016 10:29

hello guys, i need to help.. how i can handle the form with multiple input field values with same name? and only once view, this actually for basic questions form..
another idea i found this method:

relations = request.POST.getlist('relations')

tab questions

but the how i can handle it all? currently im doing with <input type="radio"..., but of course it couldn't work if has same name in once form. but if i use <input type="checkbox"..., the answers can be check more than 1 in once question...

agus makmun
Nov 24 2016 10:36

maybe like this:

<input type="radio" name="answer-{{ }}">

but how i can get it all in the view?

agus makmun
Nov 24 2016 11:31


In my test:

{% for answer in question.get_answers %}
    <input type="radio" name="answer-{{ }}" value={{ answer.score }}>
{% endfor %}

questions = request.POST.getlist('question')
answers = [request.POST['answer-{}'.format(q)] for q in questions]

And the results of it:

['20', '19', '16', '13', '11', '10', '9', '8', '1']
['5', '2', '3', '4', '1', '4', '4', '2', '2']