Skip to main content

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

  1. Use the following pip command to install the package:
    pip install django-server-tables
    
  2. Add the following line to your REST_FRAMEWORK configuration:
    REST_FRAMEWORK = {
         ...
         'DEFAULT_METADATA_CLASS': 'server_tables.DefaultMetaData',
     }
    

Usage

  1. Add the ListSchemaMixin to your ModelViewSet:

    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:

    {
       "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:

    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
       }
    }
    
  4. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_server_tables-0.1.3.tar.gz (5.6 kB view hashes)

Uploaded Source

Built Distribution

django_server_tables-0.1.3-py3-none-any.whl (6.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page