0

使用 django-profiles 应用程序,我想在有序列表中显示用户的配置文件。按不同领域排序,视情况而定。

现在文档说了一些关于在这里向视图传递额外参数的问题,但我不知道该怎么做,因为只是包含了 url(而不是我自己定义的)。

那么,我怎样才能传入可以在普通列表视图中使用的“order_by”部分?

4

1 回答 1

1

检查代码 [1],无法以您想要的方式更改查询集。

您最好的选择可能是自己编写这个视图,如果您愿意,可以使用现有的实现作为指导(例如,当您有一个按照您的规范订购的查询集时,您仍然可以调用 object_list)。urls.py然后通过首先声明它来覆盖您自己的配置文件列表 URL :

...
url(r'^profiles/$', path.to.my_profile_list_view, name='my_profile_list'), 

(r'^profiles/', include('profiles.urls')),
...

或为此创建一个新 URL 并在您的网站上使用它:

url(r'^ordered-profiles/$', path.to.my_profile_list_view, name='my_profile_list'),

[1] https://bitbucket.org/ubernostrum/django-profiles/src/c21962558420/profiles/views.py#cl-287

另见:https ://bitbucket.org/ubernostrum/django-profiles/src/c21962558420/profiles/urls.py

于 2012-09-10T21:08:21.840 回答