Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping filters in Django Admin

What I would like to achive is:

  • I go to admin site, apply some filters to the list of objects
  • I click and object edit, edit, edit, hit 'Save'
  • Site takes me to the list of objects... unfiltered. I'd like to have the filter from step 1 remembered and applied.

Is there an easy way to do it?

like image 732
Tomo Avatar asked Oct 07 '08 07:10

Tomo


1 Answers

Unfortunately there's no easy way to do this. The filtering does not seem to be saved in any session variable.

Clicking back twice is the normal method, but it can be unweildy and annoying if you've just changed an object so that it should no longer be shown using your filter.

If it's just a one-off, click back twice or go through the filtering again, it's the easiest way.

If you're going to be filtering more often, or you just want to learn about hacking the admin (which is pretty open and easy), you'll want to write a FilterSpec.

Have a look here and here for examples of people writing their own.

A really, really terrible way to do this would be to edit the admin interface so that after you click "Save", you are redirected to you filtered URL. I wouldn't recommend this at all, but it's an option.

Another fairly simple way to do this would be to write a generic view to show your filtered objects, then use Django forms to edit the items from there. I'd have a look at this, you'll be stunned just how little code you have to write to get a simple view/edit page going.

like image 136
Harley Holcombe Avatar answered Sep 19 '22 03:09

Harley Holcombe