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']
            queryset = RegistrationDatesSlots.objects.all().values('project', 'date')

        serialized_data = []
        for item in queryset:
            serialized_item = {
                'date': item['date'],
                'project': item['project']
        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
To view this discussion on the web visit

No comments:

Post a Comment