Skip to content

Commit dfbe921

Browse files
committed
(docs): mostly README formatting
- add more newlines - use bullets - use code blocks instead of one-line monospace - added one more usage example to shows multiple arguments
1 parent ab3243e commit dfbe921

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,26 @@ Django classes to make your models, managers, and querysets serializable, with b
55

66
## Installation
77

8-
`pip install django-serializable-model`
8+
```shell
9+
pip install django-serializable-model
10+
```
911

1012
It is expected that you already have Django installed
1113

1214
### Compatibility
1315

1416
_This was originally used in an older Django 1.5 codebase with Python 2.7._
1517

16-
<br>
17-
1818
Should work with Django 1.5-1.9 with Python 2.7.
19+
- Likely works with Django 1.10 and 1.11, though not 100% sure that `._meta.fields` usage works the same way in these.
20+
- Will have some problems with Django 2.0 as the Manager's `use_for_related_fields` has been removed.
21+
- `2to3` shows that there is nothing to change, so should be compatible with Python 3.x
22+
- Have not confirmed if this works with earlier versions of Django or Python.
1923

20-
Likely works with Django 1.10 and 1.11, though not 100% sure that `._meta.fields` usage works the same way in these.
21-
22-
Will have some problems with Django 2.0 as the Manager's `use_for_related_fields` has been removed.
23-
24-
`2to3` shows that there is nothing to change, so should be compatible with Python 3.x
25-
26-
Have not confirmed if this works with earlier versions of Django or Python.
24+
Please submit a PR or file an issue if you have a compatibility problem or have confirmed compatibility on versions.
2725

2826
<br>
2927

30-
Please submit a PR or file an issue if you have a compatibility problem or have confirmed compatibility on versions.
31-
3228

3329
## Usage
3430

@@ -177,9 +173,18 @@ print User.objects.prefetch_related('post_set').get(pk=new_user.pk).serialize('p
177173

178174
`.serialize` takes in any number of joins as its `*args` and they can be of any depth, using the same `__` syntax as `prefetch_related`. This means if your `Post` object also had `Comment` objects, you could write:
179175

180-
`User.objects.prefetch_related('post_set__comment_set').serialize('post_set__comment_set')`
176+
```python
177+
User.objects.prefetch_related('post_set__comment_set').serialize('post_set__comment_set')
178+
```
181179

182-
and get an array of `Comment` dictionaries within each `Post` dictionary.
180+
and get an array of `Comment` dictionaries within each `Post` dictionary. If your `Post` object also had `Like` objects:
181+
182+
```python
183+
joins = ['post_set__comment_set', 'post_set__like_set']
184+
User.objects.prefetch_related(*joins).serialize(*joins)
185+
```
186+
187+
<br>
183188

184189

185190
### JSON and APIs
@@ -188,6 +193,8 @@ Since `.serialize` outputs a dictionary, one can turn it into JSON simply by usi
188193

189194
If you're building an API, you can use `JSONResponse` on the dictionary as well.
190195

196+
<br>
197+
191198

192199
## How it works
193200

0 commit comments

Comments
 (0)