Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto Complete filter not support many2many filter on ListView #39

Open
rp-odoodeveloper opened this issue Oct 22, 2021 · 2 comments
Open

Comments

@rp-odoodeveloper
Copy link

When I use Many2many field in ListView that time it apply the filter only one selection. Multiselect does not work with autocomplete in ListView. Work fine with FormView.

@shamanu4
Copy link
Owner

Can you provide a code snippet to reproduce the isuue?

@rp-odoodeveloper
Copy link
Author

rp-odoodeveloper commented Oct 25, 2021

models.py
og = models.ManyToManyField('User', blank=True, through='UserOgMapping')
admin.py

class OgFilter(AutocompleteFilter):
    title = 'Company'
    field_name = 'ogs' #many2many field
    autocomplete_url = 'og-autocomplete'
    through_field = 'user' #relational table field
    forwards = [
        forward.Field(
            'user__id__exact',
            'user',
        ),
    ]

list_filter = [OgFilter]

def get_queryset(self):
       qs = Og.objects.all()

        if self.q:
            qs = qs.filter(name__istartswith=self.q)

        return qs

using this getting below error:
'ManyToManyDescriptor' object has no attribute 'get_queryset'
when I override get_queryset_for_field and use (model, '{}.through.{}'.format(name, self.throgh_field)).get_queryset()
then it filters only one selected record.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants