实现未映射到数据库的Django聚合对象

时间:2013-06-16 19:31:57

标签: python django django-models

我有一个在测试中编写的模型查询函数

contracts = Contracts.objects.all()
contractPlans = ContractPlans.objects.filter(contractnum__in = contracts)
parentorgs = Parentorgs.objects.all()


for plan in contractPlans:

    contractPlanTags = ContractPlanTags.objects.filter(contractnum = plan.contractnum)
    for planTags in  contractPlanTags:
        #do more stuff here

是否可以使用非数据库映射对象,我可以将parentorgscontractscontractPlanscontractPlanTags中的特定字段放入视图中?从本质上讲,我只想将一个普通的旧数据对象用作四组特定字段的容器包装器。

1 个答案:

答案 0 :(得分:1)

也许你需要Django Abstract Base Class

记住抽象基类不是数据库对象,因此也无法查询。