Skip to main content

Automates DRF APIs for Ant Design ProTable

Project description

Automates DRF APIs for Ant Design ProTable

drf_antd_protable automates DRF APIs for Ant Design ProTable, enabling seamless data handling with pagination, sorting, filtering, and searching support, while automatically generating frontend table configurations.

Installation

python3 -m pip install -U drf-antd-protable

Usage

1. use as viewsets

# views.py
from drf_antd_protable.viewsets import ProTableViewSet
from . import models, serializers

class MyTableViewSet(ProTableViewSet):
    queryset = models.QA.objects.all()
    serializer_class = serializers.QA_Serializer
# urls.py
from rest_framework.routers import DefaultRouter
from .views import MyTableViewSet

router = DefaultRouter()
router.register('demo_table', MyTableViewSet, basename='demo_table')

urlpatterns = [
    # ...
    path('', include(router.urls)),
    # ...
]

2. supporting columns configuration

  • hidden_fields
  • select_fields
  • sorter_fields
  • copyable_fields
  • not_search_fields
  • render_region_fields
  • render_compare_fields
  • verbose_name_map

example

class MyTableViewSet(ProTableViewSet):
    queryset = models.QA.objects.all()
    serializer_class = serializers.QA_Serializer

    hidden_fields = ['id']
    select_fields = ['department']
    sorter_fields = ['user', 'question']
    copyable_fields = ['anwser']
    not_search_fields = ['department']
    render_region_fields = ['size']
    render_compare_fields = ['count']
    verbose_name_map = {
        'size': '大小',
        'count': '数量',
    }

Endpoints

  • demo_table/columns/

  • demo_table/data/

  • demo_table/export/

Use in Frontend

import { ProTable } from '@ant-design/pro-components'
import { useRequest } from 'ahooks'
import { request } from '@umijs/max'

const DemoTable = () => {
    const columnsRequest = useRequest(async () => request('/api/demo_table/columns/'))

    return (
        <ProTable
            columns={columnsRequest.data}
            request={async (params, sorter, filter) => {
                const { current, pageSize, keyword, ...search } = params;
                const payload = {
                    sort: sorter,
                    filter: filter,
                    search: search,
                    globalSearch: keyword,
                };
                const data = await request('/api/demo_table/data/', {
                    method: 'POST',
                    data: payload,
                    params: { current, pageSize },
                })
                return data
            }}
        />
    )
}

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

drf_antd_protable-1.0.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

drf_antd_protable-1.0.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file drf_antd_protable-1.0.0.tar.gz.

File metadata

  • Download URL: drf_antd_protable-1.0.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.8

File hashes

Hashes for drf_antd_protable-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b94f950bf1d6f9a032a4d3e7135c1e1a9de3e657fc3296ab1289bd490a2a6399
MD5 3dac0b8d39a734ef8cb758729ff128f7
BLAKE2b-256 2e4f4b8607ba2633ddb14a6a672127abf20350118a6167ac3822d277145beab7

See more details on using hashes here.

File details

Details for the file drf_antd_protable-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for drf_antd_protable-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3fd6290152364b45abe5a7aa3f6762a73057c33f8ae1838b7c765eacb28d29e2
MD5 ab2e7954b563f3c6aed157990ac05d17
BLAKE2b-256 c789ce48d39870210be43deb1a00d716304d5de903e9eba4afc524e048442f34

See more details on using hashes here.

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