Lightweight Django class for a full Datatables server processing implementation.
https://datatables.net/examples/data_sources/server_side.html
After hanging around for a good integration of Datatables server processing in Django, I tested the things I found on internet but they all have the same problem, they cannot manage the ForeignKey relations as well. After all, I made it by myself.
This code was tested on Datatables 1.10.+ and Django 1.10.+.
To get it works just put datatables in your html template, like this:
```html
<!-- jQuery -->
<script src="/statics/js/vendors/jquery/dist/jquery.min.js"></script>
<!-- Datatables -->
<script src="/statics/js/vendors/datatables.net/js/jquery.dataTables.js"></script>
<!-- Datatables -->
<script>
$(document).ready(function() {
$('.datatable-responsive-serverside').DataTable({
"aLengthMenu": [
[25, 50, 100, 500, ], // -1],
[25, 50, 100, 500, ] //"All"]
],
"paging": true,
"responsive": true,
"processing": true,
"serverSide": true,
"ajax": "{% url 'appnamespace:viewname_json' %}",
// POST METHOD EXAMPLE HERE
//~ "ajax": {
//~ url: "{% url 'appnamespace:viewname_json' %",
//~ method: 'post',
//~ data: function(args) {
//~ return {
//~ "args": JSON.stringify(args)
//~ };
//~ }
//~ },
});
});
</script>
```
Requirements
------------
Download your preferred DataTables release from [here](https://datatables.net/download/).
Setup and examples
------------------
Install package in your Python environment.
````
pip install git+https://github.com/peppelinux/django-datatables-ajax.git
````
Create a view
````
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.db.models import Q
from django.http import HttpResponse, Http404
from django.http.response import HttpResponseRedirect
from django.http import JsonResponse
from .datatables import DjangoDatatablesServerProc
@login_required
def datatable_data(request):
radcheck = get_radcheck_active(request)
radius_accounts = _get_radius_accounts(request, radcheck)
model = RadiusPostAuth
columns = ['pk', 'username', 'reply', 'calling_station_id', 'date']
base_query = model.objects.filter(username__in=[i.username for i in radius_accounts]).exclude(calling_station_id='').order_by('-date')
class DTD(DjangoDatatablesServerProc):
def get_queryset(self):
if self.search_key:
self.aqs = base_query.filter(
Q(username__icontains=self.search_key) | \
Q(reply__icontains=self.search_key) | \
Q(calling_station_id__icontains=self.search_key))
else:
self.aqs = base_query.filter(username=radcheck.username)
dtd = DTD( request, model, columns )
return JsonResponse(dtd.get_dict())
````
Create an url resource
````
from django.conf.urls import include, url
from django.contrib.auth.decorators import login_required
from .views import *
urlpatterns = [
url(r'^datatable.json$', login_required(StatoUtenzaCorso_DTJson), name='datatable_json'),
]
````
Metadata
Release files for django-datatables-ajax 0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-datatables-ajax-0.8.tar.gz | 4.1 kB | Without provenance | Details for django-datatables-ajax-0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_datatables_ajax-0.8-py3-none-any.whl | Python 3 | none | any | Details for django_datatables_ajax-0.8-py3-none-any.whl |
Total release size: 9.5 kB
Release files / django-datatables-ajax-0.8.tar.gz
| Download URL | django-datatables-ajax-0.8.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b77de960eb311c4603f3c34bd0b4e4486ae6be1c0f7e32fa5333390b3a667c84
|
|
BLAKE2b-256 checksum How to use checksums |
c8c0ac4d0f9d400234e2db6628816c3c771ce436507ee69dae6e78578c49abf2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.9.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.2
|
Release files / django_datatables_ajax-0.8-py3-none-any.whl
| Download URL | django_datatables_ajax-0.8-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7344dcce2d16839dc1cc6fe29652f322ab85b0121f3a587a5fc0244bdb29b922
|
|
BLAKE2b-256 checksum How to use checksums |
2e1991921a4aa1410e3294a872e43e1c5f8e63ab6dc933b7cec31b80bf795669
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.9.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.2
|
Security for django-datatables-ajax 0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.