pivotal-energy-solutions/django-datatable-view

Double initialization of DatatableView

packerbacker3333 opened this issue · 3 comments

I am trying to pass the user object to get_queryset to filter the data. I can successfully pass it in (confirmed using print); however, every time I refresh the page, the datatable initializes twice, and I lose the user object on the second initialization. I have verified that the double initialization is specific to Datatables by using print in other init functions.

Are there any common issues you have seen with this? If not, I can definitely provide the relevant source code.

Thanks!

I'm having the same issue. Any progress on this?

Yes. I was able to modify their source code to do it. In my Django view, I can now use:

Your_View.get_datatable(self.request)
Instead of
Your_View.get_datatable()

Then in the DatatableView class based view I can define:

def get_queryset(self, **kwargs):
return Your_Model.objects.filter(user=kwargs[‘user’])

i put my changes on git and pypi if you’re interested. I did not spend any time explaining what I changed or writing documentation but I’ve had this deployed for a month now and it definitely works (I have a site with ~100 users that log in and use the tables).

Thanks for responding! Where do you implement Your_View.get_datatable()? Do you override that in the DatatableView class? My code looks like this:

class DetailDatatable(ValuesDatatable):
    class Meta:
        columns = ['name','id','balance']

class DetailTableListView(DatatableView):
    model = Detail
    datatable_class = DetailDatatable
    template_name = 'detail_datatable.html'

   def get_queryset(self, **kwargs):
      return model.objects.filter(id=kwargs['id'])