>>> queryset = monthlyCostTable(getMonthlyCostQuery(2020, 'region'))
Your class monthlyCostTable does not take any parameter while you are passing getMonthlyCost... you know better what your doing but this line is the root cause...
On Thursday, September 17, 2020 at 4:00:08 PM UTC-4 pcar...@gmail.com wrote:
The actual trace coolguy isTypeError at /functions/ClassMonthlyCost/object() takes no parametersRequestMethod: GETRequestVersion: 2.2.4ExceptionType: TypeErrorExceptionValue: object() takes no parametersExceptionLocation: /home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/core/handlers/base.py in _get_response, line 113PythonExecutable: /home/db_user/ciopsdb/venv/bin/pythonPythonVersion:3.6.8Python Path:
['/home/db_user/ciopsdb', '/usr/lib64/python36.zip', '/usr/lib64/python3.6', '/usr/lib64/python3.6/lib-dynload', '/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages', '/home/db_user/ciopsdb/venv/lib/python3.6/site-packages', '/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/odf', '/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/odf', '/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/odf', '/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/odf', '/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/odf', '/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/odf', '/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/odf']Server time: Thu, 17 Sep 2020 18:29:52 +0000On Thursday, September 17, 2020 at 2:26:32 PM UTC-5 coolguy wrote:is there any specific line number that message is pointing too. Can you share the actual error message and its trace...On Thursday, September 17, 2020 at 2:35:53 PM UTC-4 pcar...@gmail.com wrote:Hello everyone, I am trying to utilize the SIngleTableMixin of django_tables2 using a custom function that queries my database and aggregates the data into a list of dictionaries. I read to use the SingleTableMixin that all I needed was an iterable containing a data structure that has a key(a list of dicts) and then to instantiate a table in tables.py and pass to a my views Class. I am getting an error when I do this TypeError: Object() takes no parameters. I have included a link to the django tables 2 doc and my code below:#views.pyfrom django_tables2.views import SingleTableMixinfrom django_tables2.export.views import ExportMixinfrom django_filters.views import FilterViewfrom django.views.generic.list import ListViewfrom django.shortcuts import renderfrom finance.models import Circuitinfotable, Budgetfrom .forms import monthlyCostFormfrom .tables import CircuitTable, monthlyCostTablefrom .filters import CircuitinfotableFilterfrom datetime import datetimefrom decimal import Decimalfrom re import subimport calendar#convert a distinct queryset into a singular list of valuesdef getList(qs, key):resultsList = []for each in qs:resultsList.append(each[key])return resultsListdef getDistinct(key):return Circuitinfotable.objects.all().values(key).distinct()def convertCurrency(val):return Decimal(sub(r'[^\d.]', '', val))def getMonthlyCostQuery(year, field):circuits = Circuitinfotable.objects.all()field_list = getList(getDistinct(field), field)results_list = []resultsDict={'field': 'None', 'Jan': 0, 'Feb': 0, 'Mar': 0, 'Apr': 0, 'May': 0, 'Jun': 0, 'Jul': 0, 'Aug': 0, 'Sep': 0, 'Oct': 0, 'Nov': 0, 'Dec': 0,'Janbw': 0, 'Febbw': 0, 'Marbw': 0, 'Aprbw': 0, 'Maybw': 0, 'Junbw': 0, 'Julbw': 0, 'Augbw': 0, 'Sepbw': 0, 'Octbw': 0, 'Novbw': 0, 'Decbw': 0}results_list.append(resultsDict)for each in field_list:if each!=None and each!='None':resultsDict={'field': '', 'Jan': 0, 'Feb': 0, 'Mar': 0, 'Apr': 0, 'May': 0, 'Jun': 0, 'Jul': 0, 'Aug': 0, 'Sep': 0, 'Oct': 0, 'Nov': 0, 'Dec': 0,'Janbw': 0, 'Febbw': 0, 'Marbw': 0, 'Aprbw': 0, 'Maybw': 0, 'Junbw': 0, 'Julbw': 0, 'Augbw': 0, 'Sepbw': 0, 'Octbw': 0, 'Novbw': 0, 'Decbw': 0}resultsDict['field'] = eachresults_list.append(resultsDict)for circuit in circuits:#If you add a field to forms.py to aggregate by then add hereif field=='region':matchField = circuit.regionelif field=='carrier':matchField = circuit.carrierelif field=='bandwidth':matchField = circuit.bandwidthelif field=='status':matchField = circuit.status#get the budget for each circuitfor budgetItem in circuit.budget_set.filter(yearnum=year):#if an item is budgeted for given monthif(budgetItem.actualmrc!=0):#Cycle through results_list to find the correct dictionaryfor each in results_list:if each['field']==matchField:#update budgetItem and bwif budgetItem != None:each[calendar.month_abbr[budgetItem.monthnum]]+=convertCurrency(budgetItem.actualmrc)if circuit.bw!= None:each[calendar.month_abbr[budgetItem.monthnum] + 'bw']+=int(circuit.bw)elif matchField==None:if budgetItem != None:results_list[0][calendar.month_abbr[budgetItem.monthnum]]+=convertCurrency(budgetItem.actualmrc)if circuit.bw!= None:results_list[0][calendar.month_abbr[budgetItem.monthnum]+'bw']+=int(circuit.bw)results_list = sorted(results_list, key=lambda i:i['field'])return results_listclass MonthlyCost(SingleTableMixin):template_name = 'functions/ClassMonthlyCost.html'context_object_name = 'qs'queryset = monthlyCostTable(getMonthlyCostQuery(2020, 'region'))#tables.pyimport django_tables2 as tablesfrom django_tables2.utils import Afrom .models import Circuitinfotableclass CircuitTable(tables.Table):class Meta:model = Circuitinfotableexport_formats = ['csv', 'xlsx']template_name = "django_tables2/bootstrap.html"Id1 = tables.Column(linkify={"viewname": "viewLit", "args": [tables.A('id1__pk')]})fields = ("id1", "circuitid", "bandwidth", "region", "carrier", "segmentname", "status", "mrcnew", "diversity", )class monthlyCostTable(tables.Table):field = tables.Column()Jan = tables.Column()Janbw = tables.Column()Feb = tables.Column()Febbw = tables.Column()Mar = tables.Column()Marbw = tables.Column()Apr = tables.Column()Aprbw = tables.Column()May = tables.Column()Maybw = tables.Column()Jun = tables.Column()Junbw = tables.Column()Aug = tables.Column()Augbw = tables.Column()Sep = tables.Column()Sepbw = tables.Column()Oct = tables.Column()Octbw = tables.Column()Nov = tables.Column()Novbw = tables.Column()Dec = tables.Column()Decbw = tables.Column()Documentation Link that I am using:Anybody know where I went wrong??? If I can figure this out I really feel like I can utilize django and django_tables2 to really improve!
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/36ef7b39-e6ca-4cb9-9b48-c783552f1419n%40googlegroups.com.
No comments:
Post a Comment