Skip to main content

Framework to create dynamic data table views in Django

Project description

Django Data Tables is a Framework for Django that creates model related Data Tables that fetch filtered data via AJAX Requests and allow different actions on model instances.

This is a reimplementation of a libary that was developed and heavily used in a big inhouse enterprise software at Studitemps GmbH. This implemetation is still in a very early stage of development. You can play around but expect a few breaking changes before reaching version 1.0.0.

Detailed documentation is still missinig but will be added hopefully soon.

Quick start

1. Add “django_data_tables” to your INSTALLED_APPS in your settings.py like this:

INSTALLED_APPS = [
    ...
    'django_data_tables',
    ...
]

2. Include the autodiscover and URLconf in your project urls.py like this:

from django_data_tables.utils import autodiscover as ddt_autodiscover
from django_data_tables import views as dt_views

ddt_autodiscover()

...
path('ddt/get_data/<table_name>/', dt_views.get_data, name='ddt-get_data'),
path('ddt/action/<table_name>', dt_views.action, name='ddt-action'),
...

3. Create a tables.py in an app where you want to create a data table with something like this:

import django_data_tables as ddt

from .forms import MyEditForm

class EditAction(ddt.FormAction):
     name = 'Edit'
     form_class = MyEditForm

     def success(self, form, obj):
         form.save()


class BaseDataTable(ddt.DataTable):
     columns = [
        ddt.IdColumn('id'),
        ddt.ModelFieldColumn('<some existing field e.g. "name">',
        ddt.ActionColumn('Do')
     ]
     filters = {'id_filter': ddt.IntFilter('id'),}
     actions = [EditAction,]
     model = '<your_app_name>.<YourModel>'

4. In your view create a table renderer instance and pass it into the renderers context. So in your apps views do something like that:

from .tables import BaseDataTable

...

def my_fancy_view(request):
    table = BaseDataTable().get_renderer(request)
    return render(request, 'app/my_views_template.html', {'table': table})

5. In my_views_template.html render the table (very similar to django forms:

<html>
    <head>
    {{ table.media }}
    </head>
    <body>
        <h1>Example for a Django Data Table Renderer</h1>
        {{ table }}
    </body>
</html>

6. Create a route to your view in urls as usual an test it

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_data_tables-0.4.3.tar.gz (17.6 kB view details)

Uploaded Source

File details

Details for the file django_data_tables-0.4.3.tar.gz.

File metadata

  • Download URL: django_data_tables-0.4.3.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for django_data_tables-0.4.3.tar.gz
Algorithm Hash digest
SHA256 3d7dca72fda9dc426af5c91425ca2a358442c085bfb31070b6679a6e4522f617
MD5 d143a4bfc8b562e3ce8393df871f8e89
BLAKE2b-256 e095249fbbc302a4c84b4576132c29c18bcbd09976a19e8b35e3f2b8db704f9c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page