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

Double initialization of DatatableView #233

Open
packerbacker3333 opened this issue Aug 20, 2019 · 3 comments
Open

Double initialization of DatatableView #233

packerbacker3333 opened this issue Aug 20, 2019 · 3 comments

Comments

@packerbacker3333
Copy link

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!

@waltonereed
Copy link

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

@packerbacker3333
Copy link
Author

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

@waltonereed
Copy link

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

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