django : How to write alias in queryset

后端 未结 5 1796
甜味超标
甜味超标 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:59

    Your reason in the comment makes no sense. Each field in the model has its own column in the database, and there's never any danger of mixing them up. You can of course tell a field to use a column name that's different from the field name:

    myfield = models.CharField(max_length=10, db_column='differentname')
    

    but I don't know if that will help you, because I still don't know what your problem is.

提交回复
热议问题