-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add count parameter to media endpoint #1665
Conversation
Signed-off-by: Racheal Mwatela <[email protected]>
Signed-off-by: Racheal Mwatela <[email protected]>
Signed-off-by: Racheal Mwatela <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the appropriate way to add non standard headers would be a header that starts with X-
. Seeing the need to have a total count makes me think we probably should implement pagination properly as there are different ways this information could have been exposed. See https://www.django-rest-framework.org/api-guide/pagination/ for more information. We also have the StandardPageNumberPagination
class in https://github.com/onaio/onadata/blob/master/onadata/libs/pagination.py#L4.
Signed-off-by: Racheal Mwatela <[email protected]>
Signed-off-by: Racheal Mwatela <[email protected]>
- Get total count of attachments per form Signed-off-by: Racheal Mwatela <[email protected]>
Signed-off-by: Racheal Mwatela <[email protected]>
def count(self, request, *args, **kwargs): | ||
response = {} | ||
xform = request.query_params.get('xform') | ||
total_count = Attachment.objects.filter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is best we rely on using self.filter_queryset(self.get_queryset())
so that we maintain the queryset and filters to applied to it by the viewset. Hence
data = {
"count": self.filter_queryset(self.get_queryset()).count()
}
return Response(data=data)
Signed-off-by: Racheal Mwatela <[email protected]>
Signed-off-by: Racheal Mwatela <[email protected]>
Fixes issue #1664