1

I've got a model with boolean fields visible and hidden in using the admin.py I think it's possible to add a default filter to the page /admin/articles/article/ so it has filter by visible=True and hidden=True

class ArticleAdmin(admin.ModelAdmin):
    list filter = [...]
    ...
    def changelist_view(self, request, extra_context=None):
        if not request.GET: #No filter
            #Perform filter to queryset for visible and hidden = True
        return super(ArticleAdmin,self).changelist_view(request, extra_context=extra_context)
Samuel Muiruri
  • 492
  • 1
  • 8
  • 17

1 Answers1

1

Register your model in admin.py file and mention your model fields in list_filter property.

class ArticleAdmin(admin.ModelAdmin):

    list_filter=["hidden", "visible", "created", "modified"],
    ...

    def changelist_view(self, request, extra_context=None):
       if not request.GET: #No filter
          #Perform filter to queryset for visible and hidden = True
          return super(ArticleAdmin,self).changelist_view(request, extra_context=extra_context)

hope that helps!

Satendra
  • 6,755
  • 4
  • 26
  • 46
  • I already know about list_filter I wanted to have a default filter on the page /articles/article/ so it looks more neat – Samuel Muiruri Nov 10 '16 at 14:17
  • Do you want to override and extend basic Django admin templates. http://stackoverflow.com/questions/6583877/how-to-override-and-extend-basic-django-admin-templates – Satendra Nov 10 '16 at 14:28