Skip to content
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

How to set Default ordering in list api using @ordering decorator ?? #223

Open
Elixir-MeetThoriya opened this issue Jan 9, 2025 · 2 comments

Comments

@Elixir-MeetThoriya
Copy link

Elixir-MeetThoriya commented Jan 9, 2025

i has created_at field, i need to set default ordering = -created_at (latest first)
if I set ordering in quaryset , can't work (ninja-extra change the order)

 @http_get(
        path="",
        response={
            HTTPStatus.OK: PaginatedResponseSchema[CampaignSchema],
            HTTPStatus.INTERNAL_SERVER_ERROR: error_schema
        },
        summary="Campaign List",
        description="This endpoint retrieves a list of campaigns.",
        url_name="campaign_list"
    )
    @paginate()
    @ordering(Ordering, ordering_fields=['name'])
    @searching(Searching, search_fields=['name'])
    def list(self):
            records = self.model.objects.all().order_by("-created_at")
        return records
@Elixir-MeetThoriya Elixir-MeetThoriya changed the title How to set Default ordering in list api ?? How to set Default ordering in list api using @ordering decorator ?? Jan 9, 2025
@eadwinCode
Copy link
Owner

@Elixir-MeetThoriya I will look into this

@eadwinCode
Copy link
Owner

@Elixir-MeetThoriya, the ordering fields are particularly in this ['-created_at', 'name']. Ordering by name happened first and ordering by name followed. So the result you see is actually correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants