Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django:检查子模型的子模型是否为空?_Python_Sql_Django - Fatal编程技术网

Python Django:检查子模型的子模型是否为空?

Python Django:检查子模型的子模型是否为空?,python,sql,django,Python,Sql,Django,假设我有三个模型,一个县模型,它有许多社区。每个社区都有许多购物中心模型 我知道如果我想检查一个县是否有社区,我只需执行country.objects.filter(community\uu isnull=False).distinct(),但有什么方法可以: 找到所有有一个或多个购物中心的县 假设每一个都有一个包含存储数的整数字段。我怎样才能找到商场超过x的县 您可能想签出country.objects.filter(community\uu isnull=False,community\uu

假设我有三个模型,一个
模型,它有许多
社区
。每个
社区
都有许多
购物中心
模型

我知道如果我想检查一个县是否有社区,我只需执行
country.objects.filter(community\uu isnull=False).distinct()
,但有什么方法可以:

  • 找到所有有一个或多个购物中心的县

  • 假设每一个都有一个包含存储数的整数字段。我怎样才能找到商场超过
    x
    的县

  • 您可能想签出
    country.objects.filter(community\uu isnull=False,community\uu malls\uu stores\uu gte=1)。distinct()
    其中
    stores
    是一个包含门店数的整数字段。(这就是你想要的吗?)