Skip to content

roundware/ra-data-roundware-drf

 
 

Repository files navigation

ra-data-django-rest-framework

react-admin data and authentication provider for Django REST framework.

Stable Release license CI codecov

ra-data-django-rest-framework includes backend and client example application and tests.

ra-data-django-rest-framework

Install

npm install ra-data-django-rest-framework

Usage

import drfProvider from 'ra-data-django-rest-framework';
const dataProvider = drfProvider("/api");

Features

  • Sorting
  • Pagination
  • Filtering
  • Authentication

Sorting

Ordering for OrderingFilter is supported.

Pagination

Currently pagination with PageNumberPagination is supported.

Default PageNumberPagination has page_size_query_param set to None, overide to be able to set Rows per page, ie:

from rest_framework.pagination import PageNumberPagination


class PageNumberWithPageSizePagination(PageNumberPagination):
    page_size_query_param = 'page_size'

Filtering

ra-data-django-rest-framework supports:

Authentication

tokenAuthProvider

tokenAuthProvider uses TokenAuthentication to obtain token from django-rest-framework. User token is saved in localStorage.

tokenAuthProvider accepts options as second argument with obtainAuthTokenUrl key. Default URL for obtaining a token is /api-token-auth/.

fetchJsonWithAuthToken overrides httpClient and adds authorization header with previously saved user token to every request.

import drfProvider, { tokenAuthProvider, fetchJsonWithAuthToken } from 'ra-data-django-rest-framework';

const authProvider = tokenAuthProvider()
const dataProvider = drfProvider("/api", fetchJsonWithAuthToken);

Example app

Django application with django-rest-framework

Setup virtual envirnoment, install requirements and load initial data:

cd example/backend
virtualenv .venv
source .venv/bin/activate
pip install -r requirements.txt
./manage.py migrate
./manage.py loaddata initial

Run server:

./manage.py runserver

Admin credentials in the example app are:

admin password

React-admin demo application

yarn install # install ra-data-django-rest-framework
cd example/client
yarn install
yarn start

You can now view example app in the browser: http://localhost:3000 Login with user admin, password is password or create new users in Django admin dashboard or shell.

Contributing

This project was bootstrapped with TSDX. All features that TSDX provides should work here too.

yarn start
yarn test

TODO

  • examples for image upload

About

react-admin data provider for Django REST framework

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 75.1%
  • Python 14.5%
  • TypeScript 8.6%
  • HTML 1.8%