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 GoogleCharts and counting unique values #123

Open
PaulSec opened this issue Aug 8, 2017 · 1 comment
Open

Issue with GoogleCharts and counting unique values #123

PaulSec opened this issue Aug 8, 2017 · 1 comment

Comments

@PaulSec
Copy link

PaulSec commented Aug 8, 2017

Hi,

It seems that you don't handle the dictionaries properly in your code, check this simple code:

    isps = Ip.objects.all().values('isp').annotate(the_count=Count('isp'))
    data_source = ModelDataSource(isps, fields=['isp', 'the_count'])
    chart = BarChart(data_source, options={'title': "ISP Count"})

The error I get is:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/xxx/xxx/xxx/views.py", line 75, in stats
    data_source = ModelDataSource(isps, fields=['isp', 'the_count'])
  File "/usr/local/lib/python3.5/dist-packages/graphos/sources/model.py", line 36, in __init__
    self.data = self.create_data()
  File "/usr/local/lib/python3.5/dist-packages/graphos/sources/model.py", line 41, in create_data
    data.append(get_field_values(row, self.fields))
  File "/usr/local/lib/python3.5/dist-packages/graphos/sources/model.py", line 8, in get_field_values
    value = getattr(row, field)
AttributeError: 'dict' object has no attribute 'isp'
@PaulSec
Copy link
Author

PaulSec commented Aug 8, 2017

I solved the issue by replacing:

value = getattr(row, field)

to:

value = row[field]

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

1 participant