Code Monkey home page Code Monkey logo

ra-data-drf's Introduction

ra-data-drf

A React-admin data provider for backends built with Django REST Framework

Support

To use this you have to be on react-admin v2.x or similar (it still does not support major v3.x)

Installation

npm install --save ra-data-drf

Usage

// in App.js
import React from 'react';
import { Admin, Resource } from 'react-admin';
import drfProvider from 'ra-data-drf';
import { UserList } from './users';

const App = () => (
    <Admin dataProvider={drfProvider('http://path.to.api/')}>
        <Resource name="users" list={UserList} />
    </Admin>
);

export default App;

Features

This package was built to work with the default configurations of a Django app using Django REST Framework. It currently supports:

Sorting

This data provider translates react-admin's sorting requests from sort=["field","ASC"] and sort=["field","DESC"] to ordering=field and ordering=-field, respectively. react-admin only allows sorting by one column at a time, so multi-column sorting is NOT supported (even though DRF supports it).

It's intended to work with DRF's OrderingFilter, but it should work with any other sorting solution as long as it uses the same query string parameter and format.

Pagination

This data provider implements pagination using the page and page_size query string parameters, indicating the range of results we're requesting and the number of results we're expecting in the response, respectively. In order to render correctly, react-admin needs to know the total amount of results, which we can get from the count value included in the default response from DRF.

It's intended to work with DRF's PageNumberPagination, but it should work with any other pagination solution as long as it uses the same query string parameters and the response includes either a count value or a Content-range header with the total number of results.

Filtering

Apart from those already mentioned, every other query string parameter will be considered as a filter by DRF. This is intended to work with django-filter's DjangoFilterBackend, but it should work with any other filtering solution that uses query string parameters as filters.

ra-data-drf's People

Contributors

dgideas avatar diegobano avatar ecruells avatar ekalinin avatar feliperubilar avatar ohmyguigs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ra-data-drf's Issues

Use case example

I would really appreciate if you could create an example app containing both the react-admin frontend and the django-rest-framework backend.

I am having issues with NetworkError when attempting to fetch resource. Thus, it would be very helpful to have a working app to reference to.

Updating for v3

A different style of dataProvider is required for react-admin v3.x. There is a translation tool, but overall it makes for neater code if refactored to the new object based style.

I refactored the dataProvider you supplied for v3, and put it up as a gist:
https://gist.github.com/thclark/722ea2bae42db05c38a5c583ba976c52

You'd be most welcome to pull it into this repo for your own and others' use :)

Status

There is not much action here, unfortunately. Perhaps can @FelipeRubilar enlighten us about the current status and the future of this project?

It's listed as the only provider for Django for react-admin. Thus, it would be good to have some insight. Thanks.

Error "withRef is removed" as import drfProvider from 'ra-data-drf';

Hi,
I am newbie for using "ra-data-drf".
There is an error "withRef is removed. To access the wrapped instance, use a ref on the connected component". It happens when i past the line "import drfProvider from 'ra-data-drf';" to App.js
When i comment this import line, everything is ok, but if i import it i will have error above.

  • If i install "ra-data-drf" the first(and not install react-admin) and demo, everything is ok.
  • But if i install react-admin the first, then install "ra-data-drf", react-admin notifies error above.
    ===> I try many times, the result is no change. I don't know where I am wrong ?
    Please for me some notes for this, thanks.

How to upload file using this data provider?

May I know how to upload the file using this data provider? I m using react admin to upload the attachment but I always get back the error message "The submitted data was not a file. Check the encoding type on the form." Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.