chartit / django-chartit

A Django app to plot charts and pivot charts directly from the models. Uses HighCharts and jQuery JavaScript libraries to render the charts on the webpage.
http://django-chartit.mrsenko.com/
Other
492 stars 164 forks source link

'NoneType' object is not subscriptable #57

Open toufa123 opened 6 years ago

toufa123 commented 6 years ago

'NoneType' object is not subscriptable

Exception Value: 'NoneType' object is not subscriptable

C:\Python36\lib\site-packages\chartit\templatetags\chartit.py in load_charts, line 86

atodorov commented 6 years ago

Please post the full traceback of the error as well as the code which triggers it.

toufa123 commented 6 years ago

I'm using django 2.01 and django-chartit 0.2.9

def NIS_by_Status_view(request):

Step 1: Create a DataPool with the data we want to retrieve.

ds = \
    DataPool(
        series=
        [{'options': {
            'source': Aliens.objects.raw(
                "SELECT status.medsucess AS Species Status, Count(aliens.id) AS Number FROM aliens INNER JOIN status ON aliens.status_id == status.id GROUP BY status.medsucess")},
            'terms': [
                'Species Status',
                'Number']}
        ])

# Step 2: Create the Chart object
cht = Chart(
    datasource=ds,
    series_options=
    [{'options': {
        'type': 'line',
        'stacking': False},
        'terms': {
            'Species Status': [
                'Number']
        }}],
    chart_options=
    {'title': {
        'text': 'Number of NIS by Status'},
        'xAxis': {
            'title': {
                'text': 'Species Status'}}})

# Step 3: Send the chart object to the template.
return render_to_response('mamias/dashboard.html', {'NISbySTATUS': cht})

dashboard.html

{% extends 'mamias/mamias.html' %}

<!DOCTYPE html>

MAMIAS | {% block title %} Dashboard {% endblock %} {% load chartit %} {{ NISbySTATUS|load_charts:"container" }}

Number of NIS by Status

atodorov commented 6 years ago

Post the python traceback.

Also post the results of your query.

toufa123 commented 6 years ago

I'm new in Django and how I can get the result of the query

atodorov commented 6 years ago

I'm new in Django and how I can get the result of the query

./manage.py shell and execute the query inside the shell. You will likely have to iterate over it to print the results.

toufa123 commented 6 years ago

def query(request): objs = Aliens.objects.raw("SELECT status.medsucess AS SpeciesStatus, 1 id, Count(aliens.id) as Number FROM aliens INNER JOIN status ON aliens.status_id = status.id GROUP BY status.medsucess") for obj in objs: azerty = print ( obj.Number, obj.SpeciesStatus)

having problem Traceback (most recent call last): File "", line 2, in AttributeError: 'Aliens' object has no attribute 'Number'

atodorov commented 6 years ago

your resulting object obj does not have an attribute with the name .Number. Please read Django's QuerySet API documentation and get your queries working before submitting any more comments to this issue.

This is not a general Django support forum, this issue tracker is meant only for issues related to django-chartit!

toufa123 commented 6 years ago

here is the result of the query [('native', 7), ('cryptogenic/casual', 10), ('invasive', 14), ('Established /invasive', 4), ('established', 97), ('Questionable/Established', 1), ('Questionable/Casual', 1), ('excluded', 25), ('range expansion', 1), ('casual', 107), ('questionable', 8), ('atlanic origin/invasive', 519), ('Range Expansion/Casual', 1), ('unknown', 8), ('cryptogenic', 291), ('cryptogenic/questionable', 61), ('cryptogenic/established', 267)]