Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.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
Django Distinct()不';无法处理由union()生成的queryset_Django_Django Queryset - Fatal编程技术网

Django Distinct()不';无法处理由union()生成的queryset

Django Distinct()不';无法处理由union()生成的queryset,django,django-queryset,Django,Django Queryset,我有一个模型: class Person(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=50) 如果我这样做: all_queryset = Person.objects.all() all_queryset.count() # --> 8 all_queryset.order_by('name').distinct().count()

我有一个模型:

class Person(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=50) 
如果我这样做:

all_queryset = Person.objects.all()
all_queryset.count() # --> 8
all_queryset.order_by('name').distinct().count() # --> 3
让我们将其与另一个空查询集合并:

empty_queryset = Person.object.none()
all_queryset = all_queryset.union(empty_queryset)
all_queryset.count() # --> 8
现在,
distinct()
不再工作了:

all_queryset.order_by('name').distinct().count() # --> 8 !
与此有关吗?