modlinltd / django-advanced-filters

Add advanced filtering abilities to Django admin
https://pypi.org/project/django-advanced-filters/
MIT License
771 stars 173 forks source link

[help] Using in user side #18

Closed N3TC4T closed 8 years ago

N3TC4T commented 8 years ago

Hey bro

how can I use this cool module in my user side ?

asfaltboy commented 8 years ago

By "user side" I assume you mean outside of the Django Admin? Regrettably, we have not written django-advanced-filters with the intent of being a generic query building tool.

However, the basic idea can survive outside of the admin: the forms.py contains a (mostly) generic pair of forms/form-sets that can be used to create a "user-friendly" interface for simple query construction (notice that it currently expects either to be given model_admin or model instance on initialization, to determine the model).

Additionally, the AdvancedFilter model itself has only one job: it serializes and stores the query in a database record, so you could as easily use it for anything else.

So all that is left for you, is the following:

  1. Write a template which uses the form, for creation/editing of AdvancedFilter.
  2. Use the user selected filter in your views by getting the instance of AdvancedFilter and calling instance.query to receive back a Q() object to be used to filter the target model.

If you have any other questions, hit me up on gitter.