Skip to content

Issue with GoogleCharts and counting unique values #123

Open
@PaulSec

Description

@PaulSec

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions