Skip to main content

A simple Django app for connecting the datatables 1.10 js plugin with a standard django ModelForm.

Project description

DataTablesForm is a simple Django app for connecting the datatables 1.10 js plugin with a standard django ModelForm.

Quick start

  1. Add “datatablesform” to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'datatablesform',
    ]
  2. Create a form inheriting from DataTablesForm:

    from datatablesform import forms
    ....
    class MyModelForm(forms.DataTablesForm):
        list_display = ['field1', 'field2', 'fk_field__field', 'class_method_with_allow_tags"]
    
        class Meta:
            model = MyModel
            fields = '__all__'
  3. Use the previous form in any view:

    def my_form_view(request):
        ....
        form = MyModelForm()
        #_filters = {k,v for k,v in any_model_filter_wanted}
        #_exclude = {k,v for k,v in any_model_exclude_filter_wanted}
        script_table = form.factory_table() #form.factory_table(_filters, _exclude)
        table = 'MyModel'
        return render(request, "my_form_template.html", locals())
  4. Be aware of having the needed datatables static files in your “my_form_template”, also you’ll need to create a table element and include the script_table:

    <link href="your_static_dir" rel="stylesheet"/>
    ....
    <table class="dataTable" id="table-{{table}}"></table>
    ....
    <script src="your_static_dir">...</script>
    ....
    {{script_table|safe}}
  5. You can always make an ajax request to retrieve the script or use the code to your best.

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-datatablesform-0.1.1.tar.gz (5.5 kB view details)

Uploaded Source

File details

Details for the file django-datatablesform-0.1.1.tar.gz.

File metadata

  • Download URL: django-datatablesform-0.1.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/2.7.15+

File hashes

Hashes for django-datatablesform-0.1.1.tar.gz
Algorithm Hash digest
SHA256 417bff2b78da0807f8d829922809e8e69b478296241b9eff5b9457a1b4c6e225
MD5 066aa810038a1c3dfb6e9cfd4e05e946
BLAKE2b-256 3fcc7e3a783c9867064919b115532aa81338dde7607b461eebf95a91e121fb38

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