django : How to write alias in queryset

后端 未结 5 1793
甜味超标
甜味超标 2021-02-06 04:33

How can one write an alias for the column name in django query set. Would be useful for union-style combinations of two linked field to the same foreign model (for instance).

5条回答
  •  清酒与你
    2021-02-06 04:51

    Although this could have been done before by using extra(select={'n':'m','a':'b'}), I agree that this really should have been a part of values() itself.

    To that end, and inspired by Alex's ticket, I have just posted a patch that adds this feature. I hope you'll find it useful!

提交回复
热议问题