oscarmlage / django-cruds-adminlte

django-cruds is simple drop-in django app that creates CRUD for faster prototyping
BSD 3-Clause "New" or "Revised" License
425 stars 82 forks source link

Filter functionality #40

Closed luisza closed 6 years ago

luisza commented 7 years ago

This PR is a experimental version and many test will need it, but functional filter system.

Use list_filter as list of model attributes or FormFilter objects like:

class Myclass(CRUDView):
    model = Invoice
    list_filter = ['invoice_number', 'sent', 'paid']

Filter method is based on forms and filter query set, so we use different approch compared with django admin

FormFilter is a special class used for filter content based on form.

from cruds_adminlte.filter import FormFilter
class LineForm(forms.Form):
    line = forms.ModelMultipleChoiceField(queryset=Line.objects.all())

class LineFilter(FormFilter):
    form = LineForm

class Myclass(CRUDView):
    model = Invoice
    list_filter = ['sent', 'paid', LineFilter]

Magic.., not, just and good example of how to do a multiple value search based en a reverse foreignkey.

FormFilter has this public method:

I hope filter functionality has few bugs but code preserve filter it's a complex task, and filter content with high grade of liberty is hard to do, so sorry if something not work.

oscarmlage commented 6 years ago

Sorry for being that late. I was off.