在django教程中,was_published_recently.admin_order_field ='pub_date' [英] From the django tutorial was_published_recently.admin_order_field = 'pub_date'
问题描述
来自django教程
was_published_recently.admin_order_field = 'pub_date'
这句话到底在做什么?
推荐答案
这是django的admin部分的参考.
This is in reference to the admin section of django.
In the admin section corresponding to models, each models has a property called list_display
, which control which fields are displayed on the change list (list display of all the objects) page of the admin.
现在,如果您希望在 list_display
中更改 was_published_recently
的默认排序顺序,则可以通过设置 admin_order_field
属性来进行.
Now, if you wish to change the default sort order for was_published_recently
in the list_display
you can do so by setting the admin_order_field
attribute.
因此,在示例中:
class Poll(models.Model):
# ...
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
was_published_recently.admin_order_field = 'pub_date'
was_published_recently.boolean = True
was_published_recently.short_description = 'Published recently?'
您要添加一个名为 was_published_recently
的自定义列,并在列 was_published_recently <的"sort"选项中将排序顺序指定为数据库字段
pub_date
./code>单击.
You are adding a custom column called was_published_recently
and specifying the sort order to be the database field pub_date
when the "sort" option for the column was_published_recently
is clicked.
通过滚动到 查看全文