bobthemac bobthemac - 29 days ago 5x
Python Question

How do you use django-datatable-view

I am currently building a project that will be displaying quite a bit of data in the Django admin I would like to substitute the list view used for datatables using django-datatable-view it says in the list for features that it can be dropped in as a replacement for list view. I might be not reading this correctly but from that I think it means totally replace list view so data tables are used by default which is what I want. I am new to Django and there seems to be no documentation on this add-on they have a few samples but no docs on how to actually use features they claim exist has anyone replaced the list view in Django with datatables using this add-on. I want to try and do it by default for all new models created but also the models like auth that I haven't extended yet.


Well, I have tested this app on my localhost, here is some results(too much for comment, so I will answer here)

First, you need to take a look here:

It has got some documentation about how to implement django-datatable-view. For example: has got how to write a view to implement a table based on a model, has got how to get orders in table, has got information about js.

Better if you clone the repo and run it in localhost. There you will be able to experiment with the views and templates(as I tried to do/did).

In here:, you will see how multiple types of view(For no configuration table, specific column table etc) has been coded.

Second, what have I tried so far: My structure for this project was like this:


*From cloned repo, I copied datatableview folder and pasted it in my project.

In myapp>models:

class Post(models.Model):
       title= models.CharField(max_length=150)
       body = models.TextField()
       created = models.DateField() 

In myapp>views:

class MyView(DatatableView):
    model = Post
    datatable_options = {
        'columns': [

In myapp>urls:

url(r'^$', MyView.as_view(),  name='myview'),

In templates: in (tempaltes/myapp/post_list.html)

{% block content %}
{{ datatable }}
{{ object_list }} 
{% endblock %}

Result was like this:

title   body    created
[<post: one >, <post: two>]

here title body created are names of table's column header.

PS: I know its not much of a help, but hopefully this information will help you go further. And a little recommendation, please take a look at django-tables2