GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Solves ticket 6585:
(uses the modeladmin ordering if provided, else falls back to model ordering)
Also added 2 people to the AUTHORS (contributors on this and past tickets)
If the ModelAdmin of a Model defines ordering, ForeignKey fields to t…
…hat model respect the ordering
If the ModelAdmin of a Model defines ordering, ManyToMany fields to t…
Ordering can be dynamic, respect that ordering too
Repeated queryset logic is now an instance method
Get_ordering returns empty tuple instead of None
Added tests for the ordering on related model fields in the admin
Added 2 people to the contributors list (both worked on the ticket, p…
…lus older contributions)
(pull request done as part of #sprints-django-ar :)
If I understand correctly. This isn't needed.
See ramiro/django@master...6585-admin-dropdown-uses-modeladmin-ordering for a WIP review.
I understand it's needed. You have two different scenarios: the admin building the form field, or another thing building the form field. The default behaviour is this code, which uses the model ordering (Meta....). But you can override specifying the queryset kwarg, and that is what the admin does (changes to options.py) to override the Meta ordering with the ModelAdmin ordering. You can't expect to always have the argument, because of the situations when the field is being build outside the admin. And you can't ignore the argument because of the situations when the admin is building the field, asking for a specific queryset. Am I wrong?
more info: the added tests should expose both scenarios, so it would be a good thing to run them with and without this, to be sure.
update: my bad, was missunderstanding what was being done with defaults. You are right, that change isn't needed, and the tests prove that also.
Merged in d9330d5.. Thanks!