Skip to content

Commit 4fe2399

Browse files
author
Colton Provias
committed
Finishing models documentation
1 parent b9f128f commit 4fe2399

3 files changed

Lines changed: 66 additions & 5 deletions

File tree

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# SQLAlchemy-JSONAPI Changelog
22

3-
## 1.0.0 - 1.0 Compatibility
3+
## 1.0.0 - Start of 1.0 Compatibility
44

55
*In Development*
66

77
* BREAKING Complete rewrite for JSON API 1.0 compatibility
8+
* Switching to Semantic Versioning
89

910
## 0.2 - Querying and View Permissions
1011

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
# sqlalchemy-jsonapi
1+
# SQLAlchemy-JSONAPI
22

3-
[JSON API](http://jsonapi.org/) implementation for use with [SQLAlchemy](http://www.sqlalchemy.org/).
3+
[JSON API](http://jsonapi.org/) implementation for use with
4+
[SQLAlchemy](http://www.sqlalchemy.org/).
45

5-
**CRITICAL: This version is in complete redevelopment to include 1.0 compatibility, permission checks, custom descriptors, etc. Do not use in production unless you have a masochistic side.**
6+
SQLAlchemy-JSONAPI aims to implement the JSON API spec and to make it as simple
7+
to use and implement as possible.
8+
9+
* [Documentation](http://sqlalchemy-jsonapi.readthedocs.org)
10+
11+
# Installation
12+
13+
```shell
14+
pip install sqlalchemy-jsonapi
15+
```

docs/models.rst

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ know, and it's quite useful!
2323
Attribute Descriptors
2424
=====================
2525

26+
Sometimes, you may need to provide your own getters and setters to attributes::
27+
2628
from sqlalchemy_jsonapi import attr_descriptor, AttributeActions
2729

2830
class User(Base):
@@ -37,8 +39,56 @@ Attribute Descriptors
3739
def id_setter(self, new_id):
3840
self.id = UUID(new_id)
3941

42+
Note: id is not able to be altered after initial setting in JSON API to keep it
43+
consistent.
44+
4045
Relationship Descriptors
4146
========================
4247

48+
Relationship's come in two flavors: to-one and to-many (or tranditional and
49+
LDS-flavored if you prefer those terms). To one descriptors have the actions
50+
GET and SET::
51+
52+
@rel_descriptor(RelationshipActions.GET, 'significant_other')
53+
def getter(self):
54+
# ...
55+
56+
@rel_descriptor(RelationshipActions.SET, 'significant_other')
57+
def setter(self, value):
58+
# ...
59+
60+
To-many have GET, APPEND, and DELETE::
61+
62+
@rel_descriptor(RelationshipActions.GET, 'angry_exes')
63+
def getter(self):
64+
# ...
65+
66+
@rel_descriptor(RelationshipActions.APPEND, 'angry_exes')
67+
def appender(self):
68+
# ...
69+
70+
@rel_descriptor(RelationshipActions.DELETE, 'angry_exes')
71+
def remover(self):
72+
# ...
73+
74+
4375
Permission Testing
44-
==================
76+
==================
77+
78+
Permissions are a complex challenge in relational databases. While the
79+
solution provided right now is extremely simple, it is almost guaranteed to
80+
evolve and change drastically as this library gets used more in production.
81+
Thus it is advisable that on every major version number increment, you should
82+
check this section for changes to permissions.
83+
84+
Anyway, there are currently four permissions that are checked: GET, CREATE,
85+
EDIT, and DELETE. Permission tests can be applied module-wide or to specific
86+
fields::
87+
88+
@permission_test(Permissions.VIEW)
89+
def can_view(self):
90+
return self.is_published
91+
92+
@permission_test(Permissions.EDIT, 'slug')
93+
def can_edit_slug(self):
94+
return False

0 commit comments

Comments
 (0)