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

Issue with Global and Column Search when using PositiveIntegerField. #88

Open
kieriosity opened this issue May 30, 2022 · 1 comment
Open

Comments

@kieriosity
Copy link

I'm having an issue with the global search. When I attempt to search, I receive an "AttributeError: 'int' object has no attribute 'lower'" error. The error is obvious; you can't apply lower to int. I modified the code (below) on my local copy to cast all input variables to string and it worked, but I'm not sure if that will break something else or if it's band-aiding an issue with my code elsewhere.

The issue appears to be related to the report_year column in my code. It's a PostiveIntegerField. I have another PostiveIntegerField for the month, but it's using the string value from the list, so that is probably why it's not causing issues.

The column search is also not working unless I switch it to choices.

Model Code

This is looping and adding year values for every year since 1970 to the list.

    YEARCHOICES = []
    for r in range(1970, (datetime.datetime.now().year + 1)):
        YEARCHOICES.append((r, r))

This is the model field.

    report_year = models.PositiveIntegerField('report_year',
                                              choices=YEARCHOICES,
                                              default=datetime.datetime.now().year)

The column definition for the AjaxDatatableView
{'name': 'report_year', 'visible': True, 'choices': True, 'title': 'Report Year', },

Code changes that work for global. I didn't modify the column search because choices worked.

Changed pattern.lower() to str(pattern).lower() and text.lower() to str(text).lower()

    def search_in_choices(self, pattern_list):
        if not self._allow_choices_lookup:
            return []
        # return [matching_value for key, matching_value in
        # six.iteritems(self._search_choices_lookup) if key.startswith(value)]
        values = []
        if type(pattern_list) != list:
            pattern_list = [pattern_list]
        for pattern in pattern_list:
            pattern = str(pattern).lower()
                # values = [key for (key, text) in self._choices_lookup.items() if text.lower().startswith(pattern)]
            values += [key for (key, text) in self._choices_lookup.items() if pattern in str(text).lower()]
        return values

Am I missing something obvious or doing something incorrectly?

@morlandi
Copy link
Owner

Thank you @kieriosity for report this with so much and useful details.
I will try to reproduce it as soon as time allows

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