Using a QuerySet instead of a Model
mauroka opened this issue · 4 comments
Hello, thanks a lot for this great app.
Is there a way to use a QuerySet instead of a Model in the Class View?
Let's say instead of:
model = Entry
Something like:
model = Entry.objets.filter()
Thanks a lot for the help.
Mauro
The view is actually just a normal Django ListView with a special step added to support the table. You can use something like the following on the view:
class MyView(DatatableView):
model= Entry
def get_queryset(self):
return Entry.objects.filter(blog__user=self.request.user)
Hello @tiliv, is there a way to combine Multiple Models in the same datatable?
Let's say Model1 and Model2, and then in get_queryset return a combination of both Querysets?
I have tried to combine them with itertools but it doesn't seems to work, because it expects a queryset.
Any ideas of a workaround?
Thanks a lot for the help.
Mauro.
To complete the loop on this (sorry I never responded), I don't have an official way to chain disparate querysets together. Conceivably you could hack it together if the column specs were generic enough (or if the columns were all "virtual" [i.e., no sources
] and acquired their values at serialization-time in each column's processor callback.
The other alternative is to arrange to send a list to the datatable constructor instead of a queryset, but then you lose all database features (so it's basically a dealbreaker for large datasets).
I don't generally recommend trying to make it work this way. You may find more success using a MultipleDatatableView
and presenting the tables together and configure them both to use the same filter input.
My feeling is that this is a fringe use case that is too difficult to plan for. I'm open to discussing how it might be made easy, but I don't think there's a lot of precedent to support something like it.