【发布时间】:2012-01-18 16:38:47
【问题描述】:
我正在尝试通过我在模型中定义的属性来订购查询集,但不确定执行此操作的最佳方法。这是属性:
@property
def name(self):
if self.custom_name:
return self.custom_name
else:
return self.module_object.name
基本上,我想做一个:
things = Thing.objects.all().order_by('-name')
但在渲染时当然会遇到 Caught FieldError:无法将关键字“名称”解析为字段。
有什么想法吗?
编辑:我知道我不能这样排序,因为@property 不是数据库字段。我的问题是如何排序,因为@property 不是数据库字段。
【问题讨论】: