3

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.

bobthemac
  • 1,172
  • 6
  • 26
  • 59
  • I think listview in django-datatable-view means https://docs.djangoproject.com/en/dev/ref/class-based-views/generic-display/#listview – ruddra Jul 08 '14 at 19:25
  • Yeah I am trying to replace it with datatables by default – bobthemac Jul 08 '14 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: https://stackoverflow.com/a/39713780/2863603 – mehmet Sep 27 '16 at 00:15
  • check also https://stackoverflow.com/questions/54740133/data-table-not-populating-data-in-django-datatable-view/55047474#55047474 – openHBP Mar 07 '19 at 21:05

1 Answers1

10

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

ruddra
  • 50,746
  • 7
  • 78
  • 101
  • is there a way to integrate [x-editable](http://vitalets.github.io/x-editable/) with [django-tables2](http://django-tables2.readthedocs.io/en/latest/)? – Kingindanord Sep 21 '17 at 08:53
  • while this answer helps, the result is certainly not desirable. How can you actually render the table instead of just the list of objects? – Jed Jan 11 '19 at 15:11