-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #326 from AltSchool/ALTOS-23940-django3
Altos 23940 support django3
- Loading branch information
Showing
35 changed files
with
637 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.7.17 3.5.8 3.6.9 3.7.5 3.8.0 | ||
3.6.9 3.7.5 3.8.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
# Dynamic REST | ||
|
||
[![Join the chat at https://gitter.im/dynamic-rest/Lobby](https://badges.gitter.im/dynamic-rest/Lobby.svg)](https://gitter.im/dynamic-rest/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
# Django Dynamic REST | ||
|
||
[![Circle CI](https://circleci.com/gh/AltSchool/dynamic-rest.svg?style=svg)](https://circleci.com/gh/AltSchool/dynamic-rest) | ||
[![PyPi](https://img.shields.io/pypi/v/dynamic-rest.svg)](https://pypi.python.org/pypi/dynamic-rest) | ||
|
@@ -11,27 +9,28 @@ See http://dynamic-rest.readthedocs.org for full documentation. | |
|
||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
|
||
# Table of Contents | ||
|
||
- [Overview](#overview) | ||
- [Maintainers](#maintainers) | ||
- [Requirements](#requirements) | ||
- [Installation](#installation) | ||
- [Demo](#demo) | ||
- [Features](#features) | ||
- [Linked relationships](#linked-relationships) | ||
- [Sideloaded relationships](#sideloaded-relationships) | ||
- [Embedded relationships](#embedded-relationships) | ||
- [Inclusions](#inclusions) | ||
- [Exclusions](#exclusions) | ||
- [Filtering](#filtering) | ||
- [Ordering](#ordering) | ||
- [Directory panel](#directory-panel) | ||
- [Optimizations](#optimizations) | ||
- [Settings](#settings) | ||
- [Compatibility](#compatibility) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
- [Overview](#overview) | ||
- [Maintainers](#maintainers) | ||
- [Requirements](#requirements) | ||
- [Installation](#installation) | ||
- [Demo](#demo) | ||
- [Features](#features) | ||
- [Linked relationships](#linked-relationships) | ||
- [Sideloaded relationships](#sideloaded-relationships) | ||
- [Embedded relationships](#embedded-relationships) | ||
- [Inclusions](#inclusions) | ||
- [Exclusions](#exclusions) | ||
- [Filtering](#filtering) | ||
- [Ordering](#ordering) | ||
- [Directory panel](#directory-panel) | ||
- [Optimizations](#optimizations) | ||
- [Settings](#settings) | ||
- [Compatibility](#compatibility) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
|
||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
|
||
|
@@ -42,42 +41,47 @@ empower simple RESTful APIs with the flexibility of a graph query language. | |
|
||
DREST classes can be used as a drop-in replacement for DRF classes, which offer the following features on top of the standard DRF kit: | ||
|
||
* Linked relationships | ||
* Sideloaded relationships | ||
* Embedded relationships | ||
* Inclusions | ||
* Exclusions | ||
* Filtering | ||
* Sorting | ||
* Directory panel for your Browsable API | ||
* Optimizations | ||
- Linked relationships | ||
- Sideloaded relationships | ||
- Embedded relationships | ||
- Inclusions | ||
- Exclusions | ||
- Filtering | ||
- Sorting | ||
- Directory panel for your Browsable API | ||
- Optimizations | ||
|
||
DREST was initially written to complement [Ember Data](https://github.com/emberjs/data), | ||
but it can be used to provide fast and flexible CRUD operations to any consumer that supports JSON over HTTP. | ||
DREST was originally written to complement [Ember](https://github.com/emberjs/data)\_\_, but it can be used to provide | ||
fast and flexible CRUD operations to any consumer that supports JSON | ||
over HTTP. | ||
|
||
## Maintainers | ||
|
||
* [Anthony Leontiev](mailto:[email protected]) | ||
* [Ryo Chijiiwa](mailto:[email protected]) | ||
* [Savinay Nangalia](mailto:[email protected]) | ||
- [Anthony Leontiev](mailto:[email protected]>) | ||
- [Savinay Nangalia](mailto:[email protected]) | ||
- [Christina D'Astolfo](mailto:[email protected]) | ||
|
||
## Contributors | ||
|
||
- [Ernesto González](mailto:[email protected]) | ||
|
||
# Requirements | ||
|
||
* Python (3.5, 3.6, 3.7) | ||
* Django (1.11, 2.0, 2.1, 2.2) | ||
* Django REST Framework (3.8, 3.9, 3.10, 3.11) | ||
- Python (3.6, 3.7, 3.8) | ||
- Django (2.2, 3.1, 3.2) | ||
- Django REST Framework (3.11, 3.12) | ||
|
||
# Installation | ||
|
||
1) Install using `pip`: | ||
1. Install using `pip`: | ||
|
||
```bash | ||
pip install dynamic-rest | ||
``` | ||
|
||
(or add `dynamic-rest` to `requirements.txt` or `setup.py`) | ||
|
||
2) Add `rest_framework` and `dynamic_rest` to `INSTALLED_APPS` in `settings.py`: | ||
2. Add `rest_framework` and `dynamic_rest` to `INSTALLED_APPS` in `settings.py`: | ||
|
||
```python | ||
INSTALLED_APPS = ( | ||
|
@@ -88,39 +92,39 @@ but it can be used to provide fast and flexible CRUD operations to any consumer | |
|
||
``` | ||
|
||
3) If you want to use the [Directory panel](#directory-panel), replace DRF's browsable API renderer with DREST's | ||
in your settings: | ||
3. If you want to use the [Directory panel](#directory-panel), replace DRF's browsable API renderer with DREST's | ||
in your settings: | ||
|
||
```python | ||
REST_FRAMEWORK = { | ||
'DEFAULT_RENDERER_CLASSES': [ | ||
'rest_framework.renderers.JSONRenderer', | ||
'dynamic_rest.renderers.DynamicBrowsableAPIRenderer', | ||
], | ||
} | ||
} | ||
``` | ||
|
||
# Demo | ||
|
||
This repository comes with a `tests` package that also serves as a demo application. | ||
This application is hosted at https://dynamic-rest.herokuapp.com but can also be run locally: | ||
|
||
1) Clone this repository: | ||
1. Clone this repository: | ||
|
||
```bash | ||
git clone [email protected]:AltSchool/dynamic-rest.git | ||
cd dynamic-rest | ||
``` | ||
|
||
2) From within the repository root, start the demo server: | ||
2. From within the repository root, start the demo server: | ||
|
||
```bash | ||
make serve | ||
``` | ||
|
||
3) Visit `localhost:9002` in your browser. | ||
3. Visit `localhost:9002` in your browser. | ||
|
||
4) To load sample fixture data, run `make fixtures` and restart the server. | ||
4. To load sample fixture data, run `make fixtures` and restart the server. | ||
|
||
# Features | ||
|
||
|
@@ -215,7 +219,7 @@ In DREST, the requirement to eagerly load (or "sideload") relationships can be e | |
For example, in order to fetch a user and sideload their groups: | ||
|
||
``` | ||
--> | ||
--> | ||
GET /users/1/?include[]=groups.* | ||
<-- | ||
200 OK | ||
|
@@ -247,7 +251,7 @@ With DREST, it is possible to sideload as many relationships as you'd like, as d | |
For example, to obtain the user with groups, locations, and groups' locations all sideloaded in the same response: | ||
|
||
``` | ||
--> | ||
--> | ||
GET /users/1/?include[]=groups.location.*&include[]=location.* | ||
<-- | ||
200 OK | ||
|
@@ -282,7 +286,7 @@ For example, to obtain the user with groups, locations, and groups' locations al | |
|
||
## Embedded relationships | ||
|
||
If you want your relationships loaded eagerly but don't want them sideloaded in the top-level, you can instruct your serializer to embed relationships instead. | ||
If you want your relationships loaded eagerly but don't want them sideloaded in the top-level, you can instruct your serializer to embed relationships instead. | ||
|
||
In that case, the demo serializer above would look like this: | ||
|
||
|
@@ -303,7 +307,7 @@ class UserSerializer(DynamicModelSerializer): | |
... and the call above would return a response with relationships embedded in place of the usual ID representation: | ||
|
||
``` | ||
--> | ||
--> | ||
GET /users/1/?include[]=groups.* | ||
<-- | ||
200 OK | ||
|
@@ -329,7 +333,7 @@ In DREST, sideloading is the default because it can produce much smaller payload | |
|
||
For example, if you requested a list of 10 users along with their groups, and those users all happened to be in the same groups, the embedded variant would represent each group 10 times. The sideloaded variant would only represent a particular group once, regardless of the number of times that group is referenced. | ||
|
||
## Inclusions | ||
## Inclusions | ||
|
||
You can use the `include[]` feature not only to sideload relationships, but also to load basic fields that are marked "deferred". | ||
|
||
|
@@ -346,7 +350,7 @@ class UserSerializer(DynamicModelSerializer): | |
name = 'user' | ||
fields = ("id", "name", "location", "groups", "personal_statement") | ||
deferred_fields = ("personal_statement", ) | ||
|
||
location = DynamicRelationField('LocationSerializer') | ||
groups = DynamicRelationField('GroupSerializer', many=True) | ||
|
||
|
@@ -373,7 +377,7 @@ This field will only be returned if requested: | |
} | ||
``` | ||
|
||
Note that `include[]=personal_statement` does not have a `.` following the field name as in the previous examples for embedding and sideloading relationships. This allows us to differentiate between cases where we have a deferred relationship and want to include the relationship IDs as opposed to including and also sideloading the relationship. | ||
Note that `include[]=personal_statement` does not have a `.` following the field name as in the previous examples for embedding and sideloading relationships. This allows us to differentiate between cases where we have a deferred relationship and want to include the relationship IDs as opposed to including and also sideloading the relationship. | ||
|
||
For example, if the user had a deferred "events" relationship, passing `include[]=events` would return an "events" field populated by event IDs, passing `include[]=events.` would sideload or embed the events themselves, and by default, only a link to the events would be returned. This can be useful for large has-many relationships. | ||
|
||
|
@@ -453,7 +457,7 @@ You can filter a user by his name (exact match): | |
... or a partial match: | ||
|
||
``` | ||
--> | ||
--> | ||
GET /users/?filter{name.icontains}=jo | ||
<-- | ||
200 OK | ||
|
@@ -516,13 +520,13 @@ You can filter a user by his name (exact match): | |
|
||
The sky is the limit! DREST supports just about every basic filtering scenario and operator that you can use in Django: | ||
|
||
* in | ||
* icontains | ||
* istartswith | ||
* range | ||
* lt | ||
* gt | ||
... | ||
- in | ||
- icontains | ||
- istartswith | ||
- range | ||
- lt | ||
- gt | ||
... | ||
|
||
See the [full list here](dynamic_rest/filters.py#L153-L176). | ||
|
||
|
@@ -558,8 +562,8 @@ DREST adds that in: | |
## Optimizations | ||
|
||
Supporting nested sideloading and filtering is expensive and can lead to very poor query performance if implemented naively. | ||
DREST uses Django's [Prefetch](https://docs.djangoproject.com/en/1.9/ref/models/querysets/#django.db.models.Prefetch) object to prevent N+1 query situations and guarantee that your API is performant. | ||
We also optimize the serializer layer to ensure that the conversion of model objects into JSON is as fast as possible. | ||
DREST uses Django's [Prefetch](https://docs.djangoproject.com/en/1.9/ref/models/querysets/#django.db.models.Prefetch) object to prevent N+1 query situations and guarantee that your API is performant. | ||
We also optimize the serializer layer to ensure that the conversion of model objects into JSON is as fast as possible. | ||
|
||
How fast is it? Here are some [benchmarks](benchmarks) that compare DREST response time to DRF response time. DREST out-performs DRF on every benchmark: | ||
|
||
|
@@ -595,7 +599,7 @@ DYNAMIC_REST = { | |
# ENABLE_SERIALIZER_OPTIMIZATIONS: enable/disable representation speedups | ||
'ENABLE_SERIALIZER_OPTIMIZATIONS': True, | ||
|
||
# DEFER_MANY_RELATIONS: automatically defer many-relations, unless | ||
# DEFER_MANY_RELATIONS: automatically defer many-relations, unless | ||
# `deferred=False` is explicitly set on the field. | ||
'DEFER_MANY_RELATIONS': False, | ||
|
||
|
@@ -626,15 +630,15 @@ DYNAMIC_REST = { | |
} | ||
``` | ||
|
||
# Compatibility | ||
# Compatibility | ||
|
||
We actively support the following: | ||
|
||
* Python: 2.7, 3.5, 3.6, 3.7 | ||
* Django: 1.11, 2.0, 2.2 | ||
* Django Rest Framework: 3.4 ~ 3.10 | ||
- Python: 3.6, 3.7, 3.8 | ||
- Django: 2.2, 3.1, 3.2 | ||
- Django Rest Framework: 3.11, 3.12 | ||
|
||
**Note:** Some combinations are not supported. For up-to-date information on actively supported/tested combinations, see the tox.ini file. | ||
**Note:** Some combinations are not supported. For up-to-date information on actively supported/tested combinations, see the `tox.ini` file. | ||
|
||
# Contributing | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Dynamic REST | ||
============ | ||
=================== | ||
|
||
**Dynamic API extensions for Django REST Framework** | ||
|
||
|
@@ -34,12 +34,13 @@ over HTTP. | |
Maintainers | ||
----------- | ||
|
||
- `Anthony Leontiev <mailto:[email protected]>`__ | ||
- `Ryo Chijiiwa <mailto:[email protected]>`__ | ||
- `Anthony Leontiev <mailto:[email protected]>`__ | ||
- `Savinay Nangalia <mailto:[email protected]>`__ | ||
- `Christina D'Astolfo <mailto:[email protected]>`__ | ||
|
||
Requirements | ||
============ | ||
|
||
- Python (2.7, 3.5, 3.6, 3.7) | ||
- Django (1.11, 2.0, 2.1, 2.2) | ||
- Django REST Framework (3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10) | ||
- Python (3.6, 3.7, 3.8) | ||
- Django (2.2, 3.1, 3.2) | ||
- Django REST Framework (3.10, 3.11, 3.12) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.