Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.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 models 在查询集集合上使用排序_Django Models_Django Queryset_Wagtail - Fatal编程技术网

Django models 在查询集集合上使用排序

Django models 在查询集集合上使用排序,django-models,django-queryset,wagtail,Django Models,Django Queryset,Wagtail,我有这个页面模型: class BlogPostPage(Page): date_published= models.DateField('Published date', blank=True, null=True) intro= models.CharField(max_length=250) body = RichTextField(blank=True) header_image = models.ForeignKey('wagtailimages.Ima

我有这个页面模型:

class BlogPostPage(Page):
    date_published= models.DateField('Published date', blank=True, null=True)
    intro= models.CharField(max_length=250)
    body = RichTextField(blank=True)
    header_image = models.ForeignKey('wagtailimages.Image', blank=True, null=True,
    on_delete=models.SET_NULL, related_name='+')
    tags = ClusterTaggableManager(through='blog.BlogPageTag', blank=True)
    categories = ParentalManyToManyField('blog.BlogCategory', blank=True)

def get_context(self, request):
        context = super().get_context(request)
        all_categories = []
        for post in self.get_siblings(inclusive=True):
            all_categories +=post.specific.categories.all()
        all_categories = sorted(set(all_categories))

        context['all_categories']= all_categories
        return context
当页面被访问时,我得到一个类型错误:

在/blog/xxx处键入错误/


“您可以根据定义排序的
参数


但是我不确定:
all\u categories+=post.specific.categories.all()

我想我发现了我的错误。我试图对BlogCategory对象进行排序,而排序方法不知道如何在哪个字段上进行排序。那么我该如何克服这一点呢?提前谢谢。