django 1.8 error: 'NoneType' object is not callable

Héléna

Please see in picture, there is a form with 2 fields. After user entry the information and submit the form. The page will redirect to another html showing the form AND the filtered database result.

The structure of my project is 1 model with 2 classes(inputform; result), 2 html and 1 views.py.

The issue now is "'NoneType' object is not callable'. So I suspect it is because the views.py , there is something wrong. Your help is really appreciated. Thanks in advance.

enter image description here

url

from result.views import ResultView,InputFormView
from django.views.generic import TemplateView,FormView,ListView

urlpatterns = patterns('',    
    url(r'^result_list/$',ResultView.as_view(),name='result'),
    url(r'^input/$',InputFormView.as_view(),name='input'), 
)

views.py

from result.forms import InputForm
from result.models import Result,Input
from django.views.generic.list import ListView
from django.views.generic import FormView
....

@csrf_exempt

class InputFormView(FormView):
    template_name = 'inputform.html'
    form = InputForm

    def get_success_url(self):  /*redirect to result page with submitted form information*/
        return ''.join(
            [
                reverse('dupont'),
                '?company=',self.request.POST.get('company'),
                '?region=',self.request.POST.get('region')
            ]
        )

class ResultView(ListView):
    context_object_name = 'result_list'
    template_name = 'result_list.html'

    def get_context_data(self, **kwargs):
        context = super(ResultView, self).get_context_data(**kwargs)
        return context

    def get_queryset(self):
        if self.request.method == 'POST':
            form = InputForm(self.request.POST)
            if form.is_valid():
                company = form.cleaned_data['company']
                region = form.cleaned_data['region']

/---Based on form entry, do the filter on the database-----/

                queryset=Result.objects.filter(region=region,company=company)
                sales=Result.objects.filter(queryset).aggregate(Sum('sales'))
                employee=Result.objects.filter(queryset).aggregate(Sum('employee'))
                departments=Result.objects.filter(queryset).aggregate(Sum('departments'))

                form.save()

                return render(request,'result_list.html',{'company':company},{'region':region},{'employee':employee},{'sales':sales},{'departments':departments})

            else:
                print form.errors
        else:
            form=InputForm()                   
        return super(ResultView,self).get_queryset()

Traceback:

    File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\core\handlers\base.py" in get_response
132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\views\generic\base.py" in view
71.             return self.dispatch(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\views\generic\base.py" in dispatch
89.         return handler(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\views\generic\edit.py" in get
205.         form = self.get_form()
File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\views\generic\edit.py" in get_form
74.         return form_class(**self.get_form_kwargs())
Exception Type: TypeError at /input/
Exception Value: 'NoneType' object is not callable

result_list.html

<div class="basicinfo">         <!--Entry Form information submitted by user-->

    <table border="1" cellpadding="1">
    <tr>
        <td align="left">Company</td>
        <td>{{ company }}</td>
    </tr>
    <tr>
        <td align="left">Region</td>
        <td>{{ region }}</td>
    </tr>
  </table>
{% endfor %}
</div>     

<!--Showing the filtered result in database-->  
<td><table border="0" cellspacing="10" cellpadding="10">
<tr><b>Sales</b></tr>
<td bgcolor="#F0F0F0"> {{sales}}</td>

</tr>
<tr><b>Employee</b></tr>
<tr>
<td bgcolor="#F0F0F0"> {{employee.employee__sum}}</td>

</tr>
<tr><b>Departments</b></tr>
<td bgcolor="#F0F0F0"> {{departments.departments__sum}}</td>
</td></table>

input.html

<div class="field">
        {{ form.company.errors }}
        <label for="{{ form.company.id_for_label }}">Company:</label>
        {{ form.company }}
</div>

<div class="field" >
<label> Select the Region:
    {{ form.region }}
        {% for region in form.region.choices %}
        <option value="region" name= "region" id="id_region">{{region}} </option>
        {% endfor %}
</label>
</div>

Upgraded views.py based on suggestion

from result.forms import InputForm
from django.views.generic import DetailView
from django.views.generic.edit import FormView,FormMixin
from django.contrib import messages
from django.template import RequestContext
from django.shortcuts import redirect
from django.db.models import Sum,Avg
from django.views.generic.detail import MultipleObjectMixin

class InputFormView(FormMixin,DetailView):
    template_name = 'inputform.html'
    form = InputForm

    def post(self, request, *args, **kwargs):
        self.object = self.get_object()
        form=self.get_form()
        if form.is_valid():
            return self.form_valid(form)
        else:
            return self.form_invalid(form)
            print form.errors

    def get(self, request, *args, **kwargs):
        view = DupontView.as_view()
        return view(request, *args, **kwargs)

    def form_valid(self, form):
        company = form.cleaned_data['company']
        region = form.cleaned_data['region']

        queryset=Result.objects.filter(company=company,region=region)
        sales=Result.objects.queryset.aggregate(Sum('sales'))
        employee=Result.objects.queryset.aggregate(Sum('employee'))
        departments=Result.objects.queryset.aggregate(Sum('departments'))

        return super(ResultView,self).form_valid(form)

    def get_success_url(self):
        return reverse('dupont', kwargs={'pk': self.object.pk})

class ResultView(MultipleObjectMixin,DetailView):
    context_object_name = 'result_list'
    template_name = 'result_list.html'


    <----how can I get the submitted information and query result here from InputFormView? Is following correct?--->

    def get(self, request, *args, **kwargs):
        self.object = self.get_object(queryset=Result.objects.filter(company=company,region=region))            
        return super(Result, self).get(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(ResultView, self).get_context_data(**kwargs)
        context['InputFormView']= self.object
        return context

    def get_queryset(self):
        return self.object. ? .all()  <---what to put here? are they  "sales","departments","employee" from database filtered result together with the form data-"region" and "company"?
Echo

please take a look at these files, maybe they will be helpful to you. https://github.com/EchoUA/Tweaks-and-Hacks/tree/master/miaomiao

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

django 1.8 error: 'NoneType' object is not callable

From Dev

Django 1.10 error, 'NoneType' object is not callable

From Dev

django-'NoneType' object is not callable

From Dev

NoneType object is not callable django admin

From Dev

custom calculation returns 'NoneType' object is not callable django

From Dev

Python Error: TypeError: 'NoneType' object is not callable

From Dev

Python timer 'NoneType' object is not callable error

From Dev

reverse(): 'NoneType' object is not callable

From Dev

TypeError: NoneType object is not callable

From Dev

reverse(): 'NoneType' object is not callable

From Dev

BeautifulSoup 'NoneType' object is not callable

From Dev

Django UserManager create_user failing with 'NoneType' object not callable

From Dev

'NoneType' object is not callable beautifulsoup error while using get_text

From Dev

'NoneType' object is not callable beautifulsoup error while using get_text

From Dev

TypeError: 'NoneType' object is not callable(is ok in windows, but have this error in linux)

From Dev

object is not callable error when creating a form in django

From Dev

'NoneType' object is not callable' in BeautifulSoup findall()

From Dev

TypeError: 'NoneType' object is not callable, BeautifulSoup

From Dev

TypeError: 'NoneType' object is not callable python

From Dev

'NoneType' object is not callable for an object that has a value?

From Dev

Django test object is not callable

From Dev

Django - 'Feed' object is not callable

From Dev

Type error if link.has_attr('href'): TypeError: 'NoneType' object is not callable

From Dev

Why do I get an error message of NoneType object is not callable when I try to call this function?

From Dev

NoneType object is not callable when adding saved FK

From Dev

Timing decorator is raising "'NoneType' object is not callable" exception

From Dev

Flask after_request 'NoneType' object is not callable

From Dev

Python class: TypeError: 'NoneType' object is not callable

From Dev

TypeError: 'NoneType' object is not callable when scraping

Related Related

  1. 1

    django 1.8 error: 'NoneType' object is not callable

  2. 2

    Django 1.10 error, 'NoneType' object is not callable

  3. 3

    django-'NoneType' object is not callable

  4. 4

    NoneType object is not callable django admin

  5. 5

    custom calculation returns 'NoneType' object is not callable django

  6. 6

    Python Error: TypeError: 'NoneType' object is not callable

  7. 7

    Python timer 'NoneType' object is not callable error

  8. 8

    reverse(): 'NoneType' object is not callable

  9. 9

    TypeError: NoneType object is not callable

  10. 10

    reverse(): 'NoneType' object is not callable

  11. 11

    BeautifulSoup 'NoneType' object is not callable

  12. 12

    Django UserManager create_user failing with 'NoneType' object not callable

  13. 13

    'NoneType' object is not callable beautifulsoup error while using get_text

  14. 14

    'NoneType' object is not callable beautifulsoup error while using get_text

  15. 15

    TypeError: 'NoneType' object is not callable(is ok in windows, but have this error in linux)

  16. 16

    object is not callable error when creating a form in django

  17. 17

    'NoneType' object is not callable' in BeautifulSoup findall()

  18. 18

    TypeError: 'NoneType' object is not callable, BeautifulSoup

  19. 19

    TypeError: 'NoneType' object is not callable python

  20. 20

    'NoneType' object is not callable for an object that has a value?

  21. 21

    Django test object is not callable

  22. 22

    Django - 'Feed' object is not callable

  23. 23

    Type error if link.has_attr('href'): TypeError: 'NoneType' object is not callable

  24. 24

    Why do I get an error message of NoneType object is not callable when I try to call this function?

  25. 25

    NoneType object is not callable when adding saved FK

  26. 26

    Timing decorator is raising "'NoneType' object is not callable" exception

  27. 27

    Flask after_request 'NoneType' object is not callable

  28. 28

    Python class: TypeError: 'NoneType' object is not callable

  29. 29

    TypeError: 'NoneType' object is not callable when scraping

HotTag

Archive