TRY THIS
from django.db.models import Count

def list(self, request, *args, **kwargs):
    project_id = self.request.query_params.get('project_id')
    if project_id:
        queryset = RegistrationDatesSlots.objects.values('project', 
'date').annotate(count=Count('project')).filter(project=project_id)
    else:
        queryset = RegistrationDatesSlots.objects.values('project', 'date')

    serialized_data = []
    for item in queryset:
        serialized_item = {
            'date': item['date'],
            'project': item['project']
        }
        serialized_data.append(serialized_item)
    return Response(serialized_data)

On Thursday, May 25, 2023 at 7:05:38 AM UTC+5:30 Muhammad Juwaini Abdul 
Rahman wrote:

> Do you realize what 'Count' do?
>
> On Thu, 25 May 2023 at 09:20, 'Mohamed Yahiya Shajahan' via Django users <
> [email protected]> wrote:
>
>>     def list(self, request, *args, **kwargs):
>>         project_id = self.request.query_params.get('project_id')
>>         if project_id:
>>             queryset = RegistrationDatesSlots.objects.values('date').
>> annotate(project=Count('project')).filter(project=project_id)
>>             # queryset = 
>> RegistrationDatesSlots.objects.filter(project=project_id).query.group_by=['project']
>>         else:
>>             queryset = RegistrationDatesSlots.objects.all().values(
>> 'project', 'date')
>>
>>         serialized_data = []
>>         for item in queryset:
>>             serialized_item = {
>>                 'date': item['date'],
>>                 'project': item['project']
>>             }
>>             serialized_data.append(serialized_item)
>>         return Response(serialized_data)
>>
>>
>> this is my views i want to group by "project" but shows only one record,
>> i know there are multiple records there 
>>
>>
>>
>>  The content of this email is confidential and intended for the 
>> recipient specified in message only. It is strictly forbidden to share any 
>> part of this message with any third party, without a written consent of the 
>> sender. If you received this message by mistake, please reply to this 
>> message and follow with its deletion, so that we can ensure such a mistake 
>> does not occur in the future.
>>
>> SAVE PAPER | Good for your planet | Good for your Business
>>
>> -- 
>> 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/016aad73-74fc-49c3-80e7-c8d68ea0a6ddn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/016aad73-74fc-49c3-80e7-c8d68ea0a6ddn%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/28b321b8-4e3b-4fee-a94b-177ab1ba76f0n%40googlegroups.com.

Reply via email to