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.
- I think listview in django-datatable-view means docs.djangoproject.com/en/dev/ref/class-based-views/…ruddra– ruddra2014-07-08 19:25:55 +00:00Commented Jul 8, 2014 at 19:25
- Yeah I am trying to replace it with datatables by defaultbobthemac– bobthemac2014-07-08 19:26:57 +00:00Commented Jul 8, 2014 at 19:26
- ruddra's answer helped me get on track with django-datatable-view project, but my answer to another question on this subject may give some other detail: stackoverflow.com/a/39713780/2863603mehmet– mehmet2016-09-27 00:15:21 +00:00Commented Sep 27, 2016 at 0:15
- check also stackoverflow.com/questions/54740133/…openHBP– openHBP2019-03-07 21:05:31 +00:00Commented Mar 7, 2019 at 21:05
1 Answer
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: http://django-datatable-view.appspot.com/
It has got some documentation about how to implement django-datatable-view. For example: http://django-datatable-view.appspot.com/zero-configuration/ has got how to write a view to implement a table based on a model,
http://django-datatable-view.appspot.com/ordering/ has got how to get orders in table,
http://django-datatable-view.appspot.com/javascript-initialization/ 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: https://github.com/pivotal-energy-solutions/django-datatable-view/blob/master/datatableview/tests/example_project/example_project/example_app/views.py, 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:
-Project manage.py -myapp(folder) views.py models.py urls.py -datatableview*(folder) -projectapp(folder) settings.py urls.py *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': [ 'title', 'body', 'created', ] } 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