外键约束示例
#models操作如下
class HostInfo(models.Model):
servername = models.CharField(max_length=)
serverip = models.CharField(max_length=)
serverpassword = models.CharField(max_length=)
server_group = models.ForeignKey("GroupInfo",to_field="id") class GroupInfo(models.Model):
caption = models.CharField(max_length=)
注意: server_group 是一个对象 里边封装了id和caption,如果想取 caption可以通过如下方法:
for row in list
row.servername
row.serverip
row.server_group.caption