[Fixed]-How to filter objects in admin?

1👍

Assuming you’re talking about non-page objects, you have two options to expose them in the admin interface: snippets and ModelAdmin.

The later is very similar to Django’s ModelAdmin (but is not the same) and you should be able to overwrite get_queryset to filter the objects like you are used to with Django.

For example, after setting up the ModelAdmin app correctly, you can do something like this:

# 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)

Leave a comment