Creating efficient database queries for hierarchical models (django)

后端 未结 3 1758
我在风中等你
我在风中等你 2021-02-06 12:07

Consider this (django) model:

class Source(models.Model):
   # Some other fields
   type = models.ForeignKey(\'Type\')

class Type(models.Model):
    # Some othe         


        
3条回答
  •  伪装坚强ぢ
    2021-02-06 12:24

    Such a structure can easily be retrieved using a recursive common table expression.

    An example is e.g. here: http://www.postgresql.org/docs/current/static/queries-with.html

提交回复
热议问题