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

gt, gte, lt, lte sound like basic operations for int and float related fields #24

Closed zerongtonywang closed 8 years ago

zerongtonywang commented 8 years ago

is it particularly hard to implement those?

asfaltboy commented 8 years ago

Shouldn't be particularly hard, if you would like to contribute, I would look for adding the operators to AdvancedFilterQueryForm.OPERATORS and related tests in test_forms.py.

For robustness, we may want to implement validation or only show operators for numeric/date fields (see issue #23).

zerongtonywang commented 8 years ago

Thanks for replying.

I've been looking through the code base for the past few hours but due to my inexperience with opensource projects I really have no idea where to start.

After adding operator to the dictionary where do i implement the function? A little lost mainly because i dont see model.objects.filter anywhere.

asfaltboy commented 8 years ago

No trouble at all mate. The way the app works is that it creates a django.db.models.Q object from the given form data, serializes it and stores it in an AdvancedFilter model instance.

Later, a user selects the filter in the admin, which triggers a call to AdvancedListFilters.queryset. Which works like other Django admin list filters returning a modified queryset filtered by the query.

I should probably add the above introduction to the documentation if it's missing.

Anyhow, I suggest you look at writing the (failing) test similarly to existing ones in test_forms.py, with the expected behavior, and then make it pass.

asfaltboy commented 8 years ago

Fixed in #25 , thanks to @pjpassa