You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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))
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?
The text was updated successfully, but these errors were encountered:
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.
This is the model field.
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()
Am I missing something obvious or doing something incorrectly?
The text was updated successfully, but these errors were encountered: