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

'NoneType' object is not subscriptable #57

Open
toufa123 opened this issue Jan 2, 2018 · 8 comments
Open

'NoneType' object is not subscriptable #57

toufa123 opened this issue Jan 2, 2018 · 8 comments

Comments

@toufa123
Copy link

toufa123 commented Jan 2, 2018

'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
Copy link
Contributor

atodorov commented Jan 4, 2018

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

@toufa123
Copy link
Author

toufa123 commented Jan 4, 2018

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' %}

<title>MAMIAS | {% block title %} Dashboard {% endblock %}</title>
 {% load chartit %}
{{ NISbySTATUS|load_charts:"container" }}
            <h4 class="header-title m-t-0 m-b-20">Number of NIS by Status</h4>

            <div class="text-center">

            </div>

            <div id="container" style="height: 320px;"></div>

        </div>
    </div><!-- end col-->

@atodorov
Copy link
Contributor

atodorov commented Jan 4, 2018

Post the python traceback.

Also post the results of your query.

@toufa123
Copy link
Author

toufa123 commented Jan 5, 2018

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

@atodorov
Copy link
Contributor

atodorov commented Jan 5, 2018

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
Copy link
Author

toufa123 commented Jan 5, 2018

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
Copy link
Contributor

atodorov commented Jan 5, 2018

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
Copy link
Author

toufa123 commented Jan 5, 2018

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)]

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