django查询在列表中查看到组类似类别记录

发布于 2025-01-20 09:05:28 字数 345 浏览 2 评论 0原文

我有我的网站在网站上显示记录这些记录是不同类别的分组记录属于类似类别的类别,并将它们显示在一起

1

  1. 列表项目1

  2. 列表项目2

  3. 列表项目3

     类mymixin:
        def get_queryset(self):
    
            返回record.Objects.all()
    
    类模型:
        category = model.charfield(max_length = 255,choices = recordScategory.Choices(true,true)
     

I have my website which displays the records on website these records are of different categories how can group the records belongs to similar category and display them together

category 1

  1. List item 1

  2. List item 2

  3. List item 3

    class Mymixin:
        def get_queryset(self):
    
            return Record.objects.all()
    
    class Model:
        category = models.Charfield(max_length=255, choices=RecordsCategory.choices(True, True)
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以笙箫默 2025-01-27 09:05:28

只是...按类别订购记录?

关于如何做到这一点:这取决于您没有透露的网站的性质,但最后,它将附加到

queryset = queryset.order_by('category')

任何QuerySet供您提供网站的内容上。并不是说您需要按照以下方式写这篇文章:应该如何编写的内容将大大差异,这取决于您的实际站点技术。

Just... order the records by category?

On how to do that: that depends on the nature of your website, which you didn't disclose, but at the end it will come to appending

queryset = queryset.order_by('category')

to whatever queryset is feeding the website. Not that you need to write this as is: how this should be written will differ greatly depending on your actual site technology.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文