How to display Datatable in django using stored procedures

Issue #62 wontfix
sumapreethi created an issue

i am using django-datatables-view for displaying data in the Datatable. When i try to use this plugin with tables i got output as i needed.I have a procedure in MySQL. How can i use procedures in data tables in django.

in models.py

from django.db import connections
class MY_UTIL:
    def log_message(self):
        cur = connections["stats"].cursor()
        cur.callproc("USP_RPT_TOP_MOS",('2018-11-05',0))
        results = cur.fetchall()
        cur.close()
        return results

in views.py:

class OrderJson(BaseDatatableView):          
    columns = ['Client','Operator','Circle','OA','DA','Message','SubmitTime']

    order_columns = ['Client','Operator','Circle','OA','DA','Message','SubmitTime']

    def get_initial_queryset(self):

        my_util = MY_UTIL()
        ret = my_util.log_message()     
        return ret  
    def render_column(self, row, column):
        return super(OrderJson, self).render_column(row, column)

when i try to do this its returning the following error TypeError: count() takes exactly one argument (0 given)

Comments (1)

  1. Maciej Wisniowski repo owner

    This library is operating on Django's querysets. If you're using cursors/stored procedures then it will not work as the result returned from your get_initial_queryset method is not a queryset. In this case you would have to either change your result to Queryset somehow or implement your own filter/ordering methods that will work on your result object.

  2. Log in to comment