Keeping filters in Django Admin

前端 未结 7 1077
走了就别回头了
走了就别回头了 2021-02-04 20:23

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\'
7条回答
  •  無奈伤痛
    2021-02-04 20:50

    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.

提交回复
热议问题