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

'AdvancedFilterQueryForm' object has no attribute 'cleaned_data' #141

Closed DuSheridan closed 2 years ago

DuSheridan commented 3 years ago

Describe the bug

Trying to create any new filter leads to AdvancedFilterQueryForm object has no attribute cleaned_data error.

Steps to reproduce

Expected behaviour

You should be able to create a filter

Details

Nader-Blnk commented 3 years ago

@DuSheridan Did you solve it?, I am facing the same problem

DuSheridan commented 3 years ago

@Nader-Blnk I've side-stepped the issue by downgrading django to 3.1.3, haven't really looked into it since.

theLastOfCats commented 3 years ago

Looks like it's broken starting after merging this PR https://github.com/django/django/pull/13627

vineetg3 commented 3 years ago

I'm facing the same issue, with django 3.2.2

DavidCrediverso commented 3 years ago

same problem :(

tovfikur commented 3 years ago

Same problem :(

urfinorg commented 3 years ago

As i can see, this issue starting from Django 3.2. I can`t reprodusing it on 3.1.13(last version of 3.1 branch)., ok, as first very dirty solution, we can override clean method of AdvancedFilterForm class, inside your admin.py

from advanced_filters import forms as adv_forms
class MyAdvancedFilterForm(adv_forms.AdvancedFilterForm):
    def clean(self):
        for form in self.fields_formset:
            if not form.is_valid():
                form.cleaned_data = {'field':'id', 'DELETE': True}
        return super().clean()
class MyAdminAdvancedFiltersMixin(AdminAdvancedFiltersMixin):
    advanced_filter_form = MyAdvancedFilterForm

# as usually
@admin.register(MyModel)
class MyModelAdmin(MyAdminAdvancedFiltersMixin, admin.ModelAdmin ):
    list_display = ('__str__', 'id', 'title', .....)
    advanced_filter_fields = (
        'id',
        'title'
        ....
    )

It`s work's, almost as expected, but it's probably broke editing form... So, you can create filters, but you can't edit it. problem of this issue: formset try validete default emty_form. This form always empty, so is_bound prorerty - False. Validation - fail, form do not create cleaned_data...

Hope, founders fix it. django-advanced-filters is really useful extension.

hzung commented 2 years ago

@urfinorg I can't edit the filter either. Is there any way to fix it?

hzung commented 2 years ago

I finally fix the above issue by adding these codes in the source and installing the extension by

cd django-advanced-filters
python3 setup.py install

Thanks to the code of @urfinorg

Here is the PR: https://github.com/modlinltd/django-advanced-filters/pull/153/files I can create a new filter or update the filter now. I don't know if there is any drawback to this fix. But at least It works for now

taut-and-yare commented 2 years ago

This seems to be fixed in the develop branch?! @DuSheridan any plans for a PyPI release that fixes this?

Aref20 commented 2 years ago

Do you fix it?

davidfstr commented 2 years ago

Recent maintainers @asfaltboy and @hugovk , this issue prevents the use of django-advanced-filters on Django 3.2+.

My understanding is that a fix has been merged to the develop branch but no release has been issued to PyPI with the fix. Any chance one of you could cut a release so that django-advanced-filters can be used on modern Django versions?

hugovk commented 2 years ago

@davidfstr Hi! I'm not a maintainer here, just contributed a PR :)

Only @asfaltboy is listed as the PyPI maintainer https://pypi.org/project/django-advanced-filters/, hopefully he can make a release soon.

asfaltboy commented 2 years ago

Thanks for the kind reminder, since this version contains a breaking change (dropping support for older Python/Django versions), it's released as 2.0.0 on pypi.

DmytroLitvinov commented 2 years ago

Hi @asfaltboy ,

Good news. May you also take a look at related PR for that issue? https://github.com/modlinltd/django-advanced-filters/pull/153

Maybe we can merge it and release to PyPI also?

asfaltboy commented 2 years ago

@DmytroLitvinov we're saying the validation issue is not fixed in 2.0 ? Can you provide some more details on what used to happen and what doesn't happen now? Would it previously let you create a filter without any value in the value field, or would it raise a validation error, and now doesn't?

DmytroLitvinov commented 2 years ago

Hi @asfaltboy , It was reported by my colleague so I just let you know about taking a look. In our case we reused library for our own needs.

asfaltboy commented 2 years ago

I wasn't able to reproduce this particular issue as described above in 2.0. I'm going to go ahead and close the issue. If there are any concerns, please let me know. If there's still some issue, kindly provide step-by-step instructions on how to reproduce the issue. And please forgive me If I missed something obvious