我将使用 FAB 快速定制 IoT APP Web 作为后端。
通过运行FAB教程和文档的示例项目, http: //127.0.0.1 :5000/contactmodelview/list/ ContactView列表页面,Contact Group显示为name,黑色,而不是id。
我克隆了设计,有1:N的关系(一个账户有很多设备,就像ContactGroup有很多联系人一样),代码如下:
模型.py
class Account(Model):
id = Column(Integer, primary_key = True)
username = Column(String(128), unique = True)
password = Column(String(128))
email = Column(String(128))
oauth = Column(String(128))
cellphone = Column(String(32))
def __repr__(self):
return self.username
class Device(Model):
id = Column(Integer, primary_key = True)
snr = Column(String(256), unique = True)
name = Column(String(128))
addr = Column(String(256))
latitude = Column(Float)
longitude = Column(Float)
status = Column(Integer)
api_id = Column(String(512))
api_key = Column(String(256))
api_dev_id = Column(String(256), unique = True)
api_dev_key = Column(String(256))
owner_id = Column(Integer, ForeignKey('account.id'))
owner = relationship("Account")
def __repr__(self):
return self.name
视图.py
class DeviceView(ModelView):
datamodel = SQLAInterface(Device)
related_views = [ApplicationView, EventView]
label_columns = {'snr':'SNR', 'api_dev_id':'Device ID', 'owner_id':'Owner'}
list_columns = ['snr','name','addr','owner_id']
show_fieldsets = [
('Summary',
{'fields':['snr','name','owner_id']}
),
('Device Info',
{'fields':'addr','latitude','longitude','status','api_id','api_key','api_dev_id','api_dev_key'],'expanded':True}
),
]
class AccountView(ModelView):
datamodel = SQLAInterface(Account)
related_views = [DeviceView]
但是,DeviceView 的列表以蓝色显示相关 ID,并且显示 No Account name。但是在 DeviceDetail 视图中,会显示帐户名称。
有什么区别?