Metadata-Version: 2.1
Name: django-server-tables
Version: 0.1.3
Summary: Utils to configure tables data on the server.
Home-page: https://github.com/Agro-Club/django-server-tables
License: MIT
Author: egrvdaniil
Author-email: d.egorov@agro.club
Requires-Python: >=3.10,<4.0
Classifier: Framework :: Django
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Software Development
Requires-Dist: django-filter (>=22.1,<23.0)
Requires-Dist: djangorestframework (>=3.14.0,<4.0.0)
Project-URL: Documentation, https://github.com/Agro-Club/django-server-tables
Project-URL: Repository, https://github.com/Agro-Club/django-server-tables
Description-Content-Type: text/markdown

# 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
1. Use the following pip command to install the package:
    ```bash
    pip install django-server-tables
    ```
2. Add the following line to your REST_FRAMEWORK configuration:
    ```python
    REST_FRAMEWORK = {
         ...
         'DEFAULT_METADATA_CLASS': 'server_tables.DefaultMetaData',
     }
    ```

## Usage
1. Add the `ListSchemaMixin` to your ModelViewSet:
   ```python
   from server_tables import ListSchemaMixin
   
   class MyViewSet(ListSchemaMixin, viewsets.ModelViewSet):
       """View set with schema endpoint."""
   ```
2. Your ViewSet will now have an additional endpoint at the URL `GET viewset_base_url/?schema`, with a response like the following:
   ```json
   {
      "field": {
         "type": "string",
         "required": true,
         "read_only": false,
         "label": "Field"
      }
   }
   ```

3. You can add additional data to the schema using the `extra_metadata_fields_info attribute` in your list serializer:
   ```python
   class MySerializer(serializers.ModelSerializer):    
       Meta:
           model = MyModel
           fields = [
               'field',
           ]
           extra_metadata_fields_info = {
               'field': {'width': 10}
           }
   ```
   Now your schema will look like this:
   ```json
   {
      "field": {
         "type": "string",
         "required": true,
         "read_only": false,
         "label": "Field",
         "width": 10
      }
   }
   ```

4. Alternatively, you can use default fields info:
   ```python
   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.
