Package: djangorestframework-datatables-editor
django-rest-framework-datatables-editorOverviewThis package provides seamless integration betweenDjango REST frameworkandDatatableswith supportingDatatables editor.It handles searching, filtering, ordering and most usecases you can imagine with Datatables.You don’t have to create a different API, your API still work exactly the same .How to useInstall$pipinstalldjangorestframework-datatables-editorIf you need the functionality of the editor, you also need to download the data editor fromhere, the JS+CSS version, and put the downloaded files instaticfolder.ConfigurationTo enable Datatables support in your project, add'rest_framework_datatables_editor'to yourINSTALLED_APPS, and modify yourREST_FRAMEWORKsettings like this:REST_FRAMEWORK={'DEFAULT_RENDERER_CLASSES':('rest_framework.renderers.JSONRenderer','rest_framework.renderers.BrowsableAPIRenderer','rest_framework_datatables_editor.renderers.DatatablesRenderer',),'DEFAULT_FILTER_BACKENDS':('rest_framework_datatables_editor.filters.DatatablesFilterBackend',),'DEFAULT_PAGINATION_CLASS':'rest_framework_datatables_editor.pagination.DatatablesPageNumberPagination','PAGE_SIZE':50,}For using Datatables editor you should use DatatablesEditorModelViewSet instead ModelViewSet or add EditorModelMixin to your views.And that’s it !Your API is now fully compatible with Datatables and will provide searching, filtering, ordering and pagination without any modification of your API code ! For using Datatables editor you should use DatatablesEditorModelViewSet instead ModelViewSet or add EditorModelMixin to your views.Configuring Datatables and Datatables editorThe URL for connecting datatables is the URL of your view with?format=datatablesThe URL connecting datatables editor is the URL of your view witheditor/Full documentation is available onRead the Docs!Also you’ll need downloadDatatables editor.Example of HTML code:<!doctype html><htmllang="en"><head><metacharset="utf-8"><title>Rolling Stone Top 500 albums of all time</title><linkrel="stylesheet"href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.css"><linkrel="stylesheet"type="text/css"href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css"><linkrel="stylesheet"href="https://cdn.datatables.net/buttons/1.5.6/css/buttons.bootstrap4.min.css"><linkrel="stylesheet"href="https://cdn.datatables.net/select/1.3.0/css/select.bootstrap4.min.css"><linkrel="stylesheet"href="/static/css/editor.bootstrap4.min.css"></head><body><divclass="container"style="font-size: .9em;"><divclass="row"><divclass="col-sm-12"><tableid="albums"class="table table-striped table-bordered"style="width:100%"><thead><tr><th>Rank</th><th>Artist</th><th>Album name</th><th>Year</th><th>Genres</th></tr></thead></table></div></div></div><scriptsrc="//code.jquery.com/jquery-3.3.1.js"></script><scriptsrc="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.min.js"></script><scriptsrc="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script><scriptsrc="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script><scriptsrc="https://cdn.datatables.net/buttons/1.5.6/js/dataTables.buttons.min.js"></script><scriptsrc="https://cdn.datatables.net/buttons/1.5.6/js/buttons.bootstrap4.min.js"></script><scriptsrc="https://cdn.datatables.net/select/1.3.0/js/dataTables.select.min.js"></script><scriptsrc="/static/js/dataTables.editor.js"></script><scriptsrc="/static/js/editor.bootstrap4.min.js"></script><script>$(document).ready(function(){editor=new$.fn.dataTable.Editor({ajax:"/api/albums/editor/?format=datatables",table:"#albums",fields:[{label:"rank",name:"rank",},{label:"artist:",name:"artist.id",type:"select"},{label:"name:",name:"name",},{label:"year:",name:"year",}]});vartable=$('#albums').DataTable({"serverSide":true,dom:"Bfrtip","ajax":"/api/albums/?format=datatables","columns":[{"data":"rank","searchable":false},{"data":"artist.name","name":"artist.name"},{"data":"name"},{"data":"year"},{"data":"genres","name":"genres.name","sortable":false},],select:true,buttons:[{extend:"create",editor:editor},{extend:"edit",editor:editor},{extend:"remove",editor:editor}]});table.buttons().container().appendTo($('.col-md-6:eq(0)',table.table().container()));});</script></body></html>ThanksThe project is based on the projectdjango-rest-framework-datatablesbyDavid Jean LouisRequirementsPython (2.7, 3.4, 3.5, 3.6, 3.7, 3.8)Django (1.9, 1.11, 2.0, 2.1, 2.2, 3.0)Django REST Framework (3.9, 3.10, 3.11)Example projectTo play with the example project, just clone the repository and run the dev server.$gitclonehttps://github.com/VVyacheslav/DRF-datatables-editor.git$cdDRF-datatables-editorActivatevirtualenv.$pipinstall-rrequirements-dev.txt$pythonexample/manage.pyrunserver$firefoxhttp://127.0.0.1:8000TestingInstall development requirements.$pipinstall-rrequirements-dev.txtRun the tests.$pythonexample/manage.pytestYou can also use the excellenttoxtesting tool to run the tests
against all supported versions of Python and Django. Install tox
globally, and then simply run:$toxIf you want to check the coverage, use:$coveragerun./example/manage.pytest$coveragereport-mChangelogVersion 0.3.3 (2020-05-17):Added support for Django 3.0Version 0.3.2 (2019-05-23):Fixed checking fields when deletingVersion 0.3.1 (2019-05-22):Fixed requirementsVersion 0.3.0 (2019-05-06):Added checking of the writable fields of Datatables Editor passed to DjangoAdded information about CSRF authorization to the documentationVersion 0.2.1 (2019-04-29):Added documentationVersion 0.2.0 (2019-04-20):Added tests for editor functionalityVersion 0.1.0 (2019-04-15):Initial release.New project released with supportingDatatables editor.The project is based ondjango-rest-framework-datatablesbyDavid Jean Louis)Version 0.5.0 (2019-03-31):The changelog bellow is the changelog ofdjango-rest-framework-datatablesbyDavid Jean Louis)Fixed total number of rows when view is using multiple filter back-endsNew meta optiondatatables_extra_jsonon view for adding key/value pairs to rendered JSONMinor docs fixesVersion 0.4.1 (2018-11-16):Added support for Django 2.1 and DRF 3.9Updated READMEVersion 0.4.0 (2018-06-22):Added top level filtering for nested serializersAdded multiple field filteringAdded a ?keep= parameter that allows to bypass the filtering of unused fieldsBetter detection of the requested formatFixed typo in Queryset.count() method nameVersion 0.3.0 (2018-05-11):Added a serializer Meta optiondatatables_always_serializethat allows to specify a tuple of fields that should always be serialized in the response, regardless of what fields are requested in the Datatables requestOptimize filtersUse AND operator for column filtering instead of OR, to be consistant with the client-side behavior of DatatablesVersion 0.2.1 (2018-04-11):This version replaces the 0.2.0 who was broken (bad setup.py)Version 0.2.0 (2018-04-11):Added full documentationRemoved serializers, they are no longer necessary, filtering of columns is made by the rendererVersion 0.1.0 (2018-04-10):Initial release.