搜索

首页  >  问答  >  正文

python - django多表查询设计

例子:

  1. A表的aa字段值为0,1

  2. B表的bb字段值为no,yes

  3. 然后输出A表信息的时候,aa字段0或1,选择输出B表的yes或no。
    就是输出A表时,aa字段内容需要改为B表的bb字段内容。

想问怎么写,也设置了外键。谢谢了

高洛峰高洛峰2888 天前415

全部回复(2)我来回复

  • 黄舟

    黄舟2017-04-18 09:18:26

    class A(model.Model):
    type=(
    (1,1),
    (2,2)
    )
    name = model.IntegerFiled(choice=type)
    b=model.ForikeyFiled('B', related_name='b_a')

    class B(model.Model):
    type=(
    (1,'是'),
    (2,'否')
    )
    name = model.IntegerFiled(choice=type)
    b=name.b.全部()

    一个例子

    回复
    0
  • PHP中文网

    PHP中文网2017-04-18 09:18:26

    雷雷

    回复
    0
  • 取消回复