Django: list all reverse relations of a model

前端 未结 3 1268
故里飘歌
故里飘歌 2020-12-15 07:59

I would like my django application to serve a list of any model\'s fields (this will help the GUI build itself).

Imagine the classes (ignore the fact that all field

3条回答
  •  萌比男神i
    2020-12-15 08:04

    This was changed (in 1.8 I think) and Olivier's answer doesn't work anymore. According to the docs, the new way is

    [f for f in User._meta.get_fields()
        if f.auto_created and not f.concrete]
    

    This includes one-to-one, many-to-one, and many-to-many.

提交回复
热议问题