These are chat archives for django/django

28th
Feb 2017
agusmakmun
@agusmakmun
Feb 28 2017 06:40

@koderNeptune the aggregate Sum should return a dict, an example in your case, when you print that total_amount should return {'getters_collected_amount__sum': 20}, you should change it to get int total;

total_amount = PairMembers.objects.filter(get_help_request_id=get_help_id).aggregate(
        Sum('getters_collected_amount'))['getters_collected_amount__sum']

But, previously.... don't use default False in your request.POST.get if you wrapped it using int, because it should return an error Integer is not callable... you should change it to default int value. an example:

getters_balance = int(request.POST.get('getters_total_amount', 0))
Miracle Ayodele
@iammiracle
Feb 28 2017 06:41
oh this is awesome @agusmakmun
thanks
agusmakmun
@agusmakmun
Feb 28 2017 06:42
your welcome.. :smiley:
Miracle Ayodele
@iammiracle
Feb 28 2017 06:42
but i wont want the record to save again once the maximum amount is reached
agusmakmun
@agusmakmun
Feb 28 2017 06:57
has continued to conversation
Gururaj Jeerge
@gururajjeerge
Feb 28 2017 08:21
Any one working with Django Rest Framework ?
Santiago Malter-Terrada
@santiagomalter
Feb 28 2017 10:13

Hello, I'm working on a quite complex query within multiple models, Case(), annotations and F() objects...

        # Match category
        queryset = queryset.annotate(
            match_category=Case(
                When(category__in=user.interests.all(), then=Value(50)),
                default=Value(0),
                output_field=IntegerField()
            )
        )

More extensive code sample: https://gist.github.com/santiagomalter/3f0fc83a3b6fe3ad948e27776033fceb
I've tried so many things but I have duplicates when I combine annotate+Case() with a m2m... distinct() doesn't work. (or I'm using it wrongly)

What I'm trying to achieve is to compare attributes of a main Model (Topic) in order to calculate a "matching" score (compared to User attributes).

Does someone have any idea about the duplicates, or is thinking of an alternative to achieve the same result?

Thanks :)