【问题标题】:django ignore ordering parameter on model definition on querydjango 在查询时忽略模型定义上的排序参数
【发布时间】:2010-08-20 09:55:12
【问题描述】:

在我的模型上我有

class Meta:
    ordering = ['title']

有没有办法我可以将它留在模型定义中,因为它在其他地方有用,但在查询中告诉它忽略它而不需要排序?

【问题讨论】:

    标签: django


    【解决方案1】:

    文档是你的朋友:http://docs.djangoproject.com/en/dev/ref/models/querysets/#order-by-fields

    New in Django 1.0: Please, see the release notes
    
    If you don't want any ordering to be applied to a query, 
    not even the default ordering,  call order_by() with no parameters.
    

    【讨论】:

      猜你喜欢
      • 2012-01-23
      • 1970-01-01
      • 1970-01-01
      • 2015-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多