Utils to configure tables data on the server.
Project description
django-server-tables
Django server tables is a library for generating json schema for (DRF)[https://www.django-rest-framework.org] list view serializer. This library provides the capability to control various attributes of a front-end table, such as column width and data type, from the back-end.
Installation
- Use the following pip command to install the package:
pip install django-server-tables
- Add the following line to your REST_FRAMEWORK configuration:
REST_FRAMEWORK = { ... 'DEFAULT_METADATA_CLASS': 'server_tables.DefaultMetaData', }
Usage
-
Add the
ListSchemaMixinto your ModelViewSet:from server_tables import ListSchemaMixin class MyViewSet(ListSchemaMixin, viewsets.ModelViewSet): """View set with schema endpoint."""
-
Your ViewSet will now have an additional endpoint at the URL
GET viewset_base_url/?schema, with a response like the following:{ "field": { "type": "string", "required": true, "read_only": false, "label": "Field" } }
-
You can add additional data to the schema using the
extra_metadata_fields_info attributein your list serializer:class MySerializer(serializers.ModelSerializer): Meta: model = MyModel fields = [ 'field', ] extra_metadata_fields_info = { 'field': {'width': 10} }
Now your schema will look like this:
{ "field": { "type": "string", "required": true, "read_only": false, "label": "Field", "width": 10 } }
-
Alternatively, you can use default fields info:
from server_tables import DefaultTableColumnTypes class MySerializer(serializers.ModelSerializer): Meta: model = MyModel fields = [ 'field', ] extra_metadata_fields_info = { 'field': DefaultTableColumnTypes.NAME, }
License
The library is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_server_tables-0.1.3.tar.gz.
File metadata
- Download URL: django_server_tables-0.1.3.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.10.9 Linux/5.15.0-1031-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c1c7490930546b212dada827cbb8a9d81ca23fa072b5cc9d776f5872297e42f
|
|
| MD5 |
2ea4a4e0681eb07c535802d1a3b17a37
|
|
| BLAKE2b-256 |
7af147a72be2f6e0a9f856d4187397d5d56f1f0efbce781711c0b89ff4c91a99
|
File details
Details for the file django_server_tables-0.1.3-py3-none-any.whl.
File metadata
- Download URL: django_server_tables-0.1.3-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.10.9 Linux/5.15.0-1031-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b024cf1e1e9de881d7b48b2113b94cf259c395aa09a4e96508487f14fc8b39f6
|
|
| MD5 |
44ecbc3af72956ebad201fd50e120f18
|
|
| BLAKE2b-256 |
a4554b087fd0001fcd4b196761bef169f8a0b7d1c6fefb2d9cfd629fe46fd6da
|