Hiya, The title says it all. It would be dead useful if you could always use fields rather than the string name of a field, for example in a QuerySet order_by(), or in the BaseModelAdmin.ordering class attribute (and probably many more locations).
This has the huge advantage of avoiding string literals in your code, which allows static code analysis (MyPy, Pycharm's inspections, etc.) tools to warn you if you misspell the field name, or if you later rename the field. Otherwise such errors end up being hidden until that line of code happens to be actually run, which has the potential to slip through testing and end up in production. It also allows refactor/rename tools to automatically assist with renames in every such location across your Django project, saving a lot of time and effort. It also seems really simple to implement. All you'd need would be a helper function that did a few if-elif checks for instances of Field or DeferredAttribute, and returned Field.name and DeferredAttribute.field.name respectively. It would return strings unchanged to preserve the current functionality. The tricky part would be then tracking down everywhere within Django where such field name strings are expected and wrapping the input in this function. Is there any chance something like this could be considered as a new feature? Thanks in advance, Matt -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/6e84d486-e2a0-47ca-b8f5-99739be3028a%40googlegroups.com.