鉴于Django的1.8,Python的2.7.5,PostgreSQL和下面的通用模型比较两个相似字段:从两个不同的模型
class restAPI(models.Model):
rest_id = models.CharField(max_length=20)
rest_host = models.CharField(max_length=20)
rest_mode = models.CharField(max_length=20)
rest_state = models.CharField(max_length=20)
class soapAPI(models.Model):
soap_id = models.CharField(max_length=20)
soap_host = models.CharField(max_length=20)
soap_asset = models.CharField(max_length=20)
soap_state = models.CharField(max_length=20)
在一个完美的世界soapAPI.soap_host
和restAPI.rest_host
将完美匹配。然而,情况很少。我正在尝试查找并返回soapAPI中不存在的任何主机,这些主机不在restAPI中。我有一个工作方法,目前我使用python解析这些数据,然后将它保存到它在django中的模型中,但我必须相信我可以使用模型本身来做到这一点(我认为这样做会更有效) 。
其中soapAPI.soap_host
在restAPI.rest_host
使用利用.raw()
由django的或提供的ORM丢失,优选地与ORM如何一个返回的soapAPI
的整模型?任何和所有的帮助将不胜感激,因为这对我来说是一种学习体验。先谢谢你。
EDIT1
完全开放以及建模为某种形式的答案的关系。
EDIT2
离开开放的,因为我不得不相信这是一个更好的办法来做到这一点不是多个查询集。
EDIT3
此外,有没有办法做到muiltiple __in
的什么?我实际上需要返回整个soapAPI
模型,其中soapAPI.soap_host
缺失restAPI.rest_host
和soapAPI.soap_state
是'活'。
无论出于何种原因,我得到这个:'FieldError:无法解析关键字'rest_host'到字段中。选择是:id,soap_asset,soap_host,soap_id,soap_state' – beardedeagle 2015-04-02 17:36:00
找出它,并用较少的代码。看到我的答案。谢谢你让我开始,但你的帮助是有帮助的。现在如果我只能弄清楚如何在一个查询集中执行此操作。 – beardedeagle 2015-04-02 17:43:19
我没有看到任何答案O.o – HassenPy 2015-04-02 17:44:29