Wednesday, May 24, 2023

group by "project"

    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 django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/016aad73-74fc-49c3-80e7-c8d68ea0a6ddn%40googlegroups.com.

No comments:

Post a Comment