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

Can ordering feature cross relations? #101

Open
ddahan opened this issue Dec 13, 2023 · 4 comments
Open

Can ordering feature cross relations? #101

ddahan opened this issue Dec 13, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@ddahan
Copy link

ddahan commented Dec 13, 2023

Hi there!

I used searching feature and was pleased to notice that search fields can cross relationships, for example with:

@searching(Searching, search_fields=["owner__first_name", "owner__last_name"])

However, I'm wondering how to have a similar behaviour with ordering feature.
As of now, it seems that it is considered to be a wrong field. For example, something like this will have no effect on ordering:

image

How can I do? Thanks a lot.

@eadwinCode
Copy link
Owner

@ddahan you mean you want searching query for and ordering action?

@ddahan
Copy link
Author

ddahan commented Dec 15, 2023

Nope, I just want to be able to "order_by" across relation.

For example, this would work in a shell:

Badge.objects.order_by("owner__first_name")

But would not work (no effect on ordering) with my api call to :

http://localost:8000/api/badges?page=1&ordering=owner__first_name

@eadwinCode
Copy link
Owner

Oh okay I see what you mean. I will take a look and revert

@eadwinCode eadwinCode added the bug Something isn't working label Aug 21, 2024
@huangjiarong
Copy link

Has this bug been fixed?
I've added foreign key related fields to ordering_fields, so I can implement sorting for them.
However, this requires me to write all sortable fields into ordering_fields.

@router.get('/', response=List[SalarySchemaOut], summary='获取研发人员工资-分页')
@paginate(MyPagination)
@ordering(Ordering, ordering_fields=['research_staff_item__item_paper__name'])
def listData(request, filters: SalaryFilterSchema = Query(...)):
    """ 获取研发人员工资 """
    queryset = ResearchSalary.add_annotate()
    queryset = queryset.filter(research_staff_item__research_staff__company=request.company)\
        .prefetch_related("research_staff_item", "research_staff_item__research_staff", "research_staff_item__item_paper")
    queryset = filters.filter(queryset)
    return queryset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants