Django管理员搜索/过滤功能作为页表 [英] Django admin search/filter functionality as a page table

查看:240
本文介绍了Django管理员搜索/过滤功能作为页表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道有没有办法在常规视图中使用Django Admin的过滤/排序/分页/搜索功能。

I was wondering if there is a way to use the power of Django Admin's filtering/ordering/paginating/search capabilities in a regular view.

我的意思是我有一个模型,一些领域。我想要一个搜索表单,其中字段的定义很像使用admin.ModelAdmin。用户将能够搜索(使用提供的字段),按值过滤,通过页面的结果表等进行分页。所有这些都没有最小的工作量,例如。只需配置哪些字段应该在表单中使用。这样的东西:

What I mean is that I have a model, some fields on it. I'd like to have a "search" form, where fields would be defined much like using admin.ModelAdmin. User would be able to search (using provided fields), filter by values, paginate through pages of result table etc. All that without minimal amount of work on my part, eg. just configuration which fields should be used in the form. Something like this:

class SchoolAdmin(ModelAdmin):
    list_display = ('id', 'name', )
    list_display_links = ('name', )
    search_fields = ('name', )
    list_filter = ('type', )

有没有这样的可用?或者我必须自己编写代码?

Is there something like this available? Or do I have to code it myself?

编辑:

我需要这样的插件/应用程序的功能是:

Features I require from such a plugin/application are:


  1. 以数据显示数据

  2. 按列排序

  3. 过滤(例如,仅显示X = Y的行)

  4. 按列搜索

  5. 可选配置与ModelAdmin样式类似

  1. Display data as a table
  2. Sorting by columns
  3. Filtering (eg. "show only rows that has X = Y")
  4. Searching by columns
  5. Optionally configuration similar to ModelAdmin style

Alasdair的 django-tables2 只匹配第一和第二个条件。

Alasdair's django-tables2 only matches 1st and 2nd conditions.

推荐答案

你提到的django功能并不是真的可重用在Django 1.3的自定义视图中。最近有一些关于django-developers组的讨论,关于分割管理功能,使其可重用。

The django functionality you mention isn't really reusable in custom views as of Django 1.3. There was recently some discussion on the django-developers group about splitting out admin functionality to make it reusable.

我遇到了两个可能对您有用的项目, django-tables2 django的滤波器。他们都提供略有不同的东西,我想你正在寻找两者的混合物。

I have come across two projects that might be useful to you, django-tables2 and django-filter. They both offer slightly different things, I think you're looking for a mixture of the two.


django-tables2简化了将数据转换成HTML表。它具有本地支持分页和排序。它对于HTML表是什么django.forms对HTML表单执行

django-tables2 simplifies the task of turning sets of data into HTML tables. It has native support for pagination and sorting. It does for HTML tables what django.forms does for HTML forms



django-filter



django-filter


Django过滤器是一个可重用的Django应用程序,允许用户动态过滤
查询。它需要Python 2.4或更高版本。对于使用和
安装说明请参阅docs目录。

Django-filter is a reusable Django application for allowing users to filter queryset dynamically. It requires Python 2.4 or higher. For usage and installation instructions consult the docs directory.

Django过滤器可用于生成类似于Django
admin的 list_filter 界面。它的API非常类似于Django的
ModelForms

Django-filter can be used for generating interfaces similar to the Django admin's list_filter interface. It has an API very similar to Django's ModelForms.

这篇关于Django管理员搜索/过滤功能作为页表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆