morlandi / django-ajax-datatable

A Django app which provides the integration of a Django project with the jQuery Javascript library DataTables.net
MIT License
208 stars 64 forks source link

Why is the model a required field? #10

Closed maksam07 closed 3 years ago

maksam07 commented 3 years ago

Hey! I am using the library: https://pypi.org/project/django-countries/ I would like to customize it and output the result via django-ajax-datatable But django-ajax-datatable only accepts a model that the other library doesn't have. Is there any way to solve this problem?

morlandi commented 3 years ago

Hello. Rendering a Django model is the very prime purpose of this project. You can add columns showing fields from related models using the "field1__field2" syntax, and customize columns contents by overriding customize_row() ... ... but still a base model which establishes the total number of rows in the table is always required. If you need to tabulare data unrelated with a Django model, I suggest you to provide a view for returning them, then use datatables.net directly. Since the total number of countries is rather limited, you might just render an HTML table (using a template) and let datatables.net handle it; no ajax should be required. I would start from this basic example: https://datatables.net/examples/data_sources/dom.html