Sum, Count works when we try to get sum/count for a column,
for this case you can try something like this
def get_yes_count_by(id):
user = User.objects.get(id=id)
count = 0
for val in user.__dict__.values():
if val == "YES":
count += 1
return count
On Tue, 21 Sept 2021 at 04:11, J.T. <[email protected]> wrote:
> I have a model called member that has 6 columns: ID, Value1, Value2,
> Value3, Value4, Value5
>
> The values in columns Value1, Value2, Value3, Value4, Value5 are either Y
> or N.
>
> I'm trying to query by ID to count the number of Y values for each member.
>
> For example one row would be: 5, Y, N, Y, N, N
>
> I would like to return: 2 (since that is the number of Y in that member's
> row)
>
> I've tried using Aggregate, Annotate, F, Q, Sum, Count in different ways
> and I'm missing the mark. I've been through the docs and SO for about 2
> hours.
> I would post my errors but it's on my work computer and I have to post
> here from my personal laptop.
>
> I feel like I may be over-thinking it but I can't quite figure it out. Any
> help would be greatly appreciated.
>
> Jason
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/597a0acf-65a0-4e9a-8a9f-b61892860789n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/597a0acf-65a0-4e9a-8a9f-b61892860789n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAGp2JVG_Cwyp7bSPfNGDcOg_VKSRtke-dHwtz5A5kRohERV4oQ%40mail.gmail.com.