OrderingFilter override


One quick question, maybe not regarding Django but more about DRF.

I have an OrderingFilter as default on my settings, and 2 classes on models:

Class A():
name = models.CharField()
Class B():
name = models.CharField()

(both fields have the same name. class B have a ForeignKey for class A)

On the View of class A, I have:
ordering_fields = ['name']

But what I really want to do is to order the objects of my class A by their names from the class B. Is there any way I can do it?

On my view I tried to annotate the queryset of the class A with “name”, where name is the name of the object B, however, it doesn’t allow to do it because “name” is already a field of the class A.

The annotation 'name' conflicts with a field on the model.

Is there any way I can specify, that I want this “name” to be the name of the class B, instead of class A, on my ordering fields?

The attribute you assign as an annotation does not need to match the name of the original field.

Thank you for your feedback Ken,

The issue is that on this case, the url would be something like website/?ordering=class_b_name which is what I am trying to avoid.

Basically the same thing, but the url should stay website/?ordering=name, instead.