Coder Social home page Coder Social logo

suqi / drf-schema-adapter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from drf-forms/drf-schema-adapter

0.0 2.0 0.0 147 KB

Making using Django with frontend libraries and frameworks DRYer

Home Page: http://drf-schema-adapter.readthedocs.io/en/latest/

License: MIT License

Python 91.61% JavaScript 7.58% Shell 0.80%

drf-schema-adapter's Introduction

DRF-schema-adapter

drf-schema-adapter is a set of tools used to make it as straight-forward to declare an API endpoint as it is to declare a new ModelAdmin in Django and export the corresponding definition to frontend frameworks and libraries

Installation

drf-schema-adapter is compatible with python 2.7 and 3.4+, Django 1.8 and DRF 3.3+

With pip

pip install drf-schema-adapter

From source

Within the source directory:

python setup.py install

Demo application

You can see a demo application running at https://djembersample.pythonanywhere.com/.

Basic usage

First of all you'll need to import the default EndpointRouter in your urls.py file.

from drf_auto_endpoint.router import router

As well as add its urls to your urlpatterns in urls.py, the same way you would with DRF's DefaultRouter.

urlpatterns = [
    ...
    url(r'^api/', include(router.urls)),
    ...
]

Prototyping

The quickest way to get a working endpoint is to register a model with the router. Register accepts an optional keyword argument for the url associated to that endpoint. By default the url for an endpoint willbe app_label/verbose_name_plural

from drf_auto_endpoint.router import router
from my_app.models import MyModel, OtherModel

router.register(MyModel)
router.register(OtherModel, url='my_custom_url')

urlpatterns = [
    url(r'^api/', include(router.urls)),
]

Adding schema information to your OPTIONS calls

Django REST framework provides the ability to customize thos calls thanks to metadata classes.

Setup DRF to use one of DRF-schema-adapter's metadata classes to get shcema information:

## settings.py

...
REST_FRAMEWORK = {
    'DEFAULT_METADATA_CLASS': 'drf_auto_endpoint.metadata.AutoMetadata',
}

Exporting to the frontend

First add 'export_app' to your setting's INSTALLED_APPS, then run:

./manage.py export --adapter_name EmberAdapter samples/products

Full documentation

For a (way) more complete documentation, please see http://drf-schema-adapter.readthedocs.io

Related projects

Contibuting guide-lines

If you'd like to contibute to DRF-schema-adapter*, you are more than welcome to do so. In order to make contributing to this project a rich experience for everyone, please follow these guide-lines:

  • First, fork the project with your own github account, build your code on your own repository and submit a pull-request once your contribution is ready
  • Before contributing a bug-fix or new feature, create an issue explaining what the problem/need is first. When submitting your pull-request, make sure to reference the original issue
  • For any code you contribute, make sure to follow PEP8 recommendation (soft line-limit 100, hard limit 120)
  • For bug-fixes, please first write a test that will fail with the current code and passes using your patch. For easier evaluation, please do so in 2 separate commits
  • For new features, if your feature can be implemented as a third-party app (like new adapters), please don't contribute them to this repo, publish your own application and open an issue telling us about it. We will make sure to add a link to your application in this README.
  • Read and respect the Code Of Conduct

ToDo

  • Write better documentation
  • Write more/better tests
  • Enable admin-like registration mechanism
  • Add languages information when django-model-translation is installed

License information available here.

Contributors code of conduct is available here. Note that this COC will be enforced.

drf-schema-adapter's People

Contributors

nanuxbe avatar adrienbrunet avatar bianchimro avatar nostalgiaz avatar

Watchers

James Cloos avatar Matt Su avatar

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.