如何过滤管理中的对象?

How to filter objects in admin?

How i can filter objects that are shown in wagtail admin page of each model? In django this problem can be solved by overriding Admin class of model, in wagtail i dont know how it is possibile.

假设您谈论的是非页面对象,您有两种选择可以在管理界面中公开它们:snippets and ModelAdmin

后面跟Django的ModelAdmin很像(但是不一样)应该可以覆盖get_queryset来像你用的那样过滤对象与 Django 一起使用。

例如,正确设置 ModelAdmin 应用程序后,您可以执行以下操作:

# models.py
class Person(django.db.models.Model):
  type = django.db.models.CharField(max_length=20, choices=(('student', 'Student'), ('teacher', 'Teacher')))
  # ...

# wagtail_hooks.py
class StudentAdmin(wagtail.contrib.modeladmin.options.ModelAdmin):
  model = my_app.models.Person

  def get_queryset(self, request):
    qs = super(StudentAdmin, self).get_queryset(request)
    return qs.filter(type='student')

wagtail.contrib.modeladmin.options.modeladmin_register(MyPageModelAdmin)