Skip to content

Commit fe4ff95

Browse files
George Bocharovgeorgebv
George Bocharov
authored andcommitted
updated readme
1 parent d49adca commit fe4ff95

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

README.md

+24-11
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030
data serialization and validation.
3131

3232
[Django REST framework](https://www.django-rest-framework.org) is a framework built
33-
on top of [Django](https://www.djangoproject.com/) which allows writing REST APIs.
33+
on top of [Django](https://www.djangoproject.com/) used to write REST APIs.
3434

35-
If like me you develop DRF APIs and you like pydantic , `drf-pydantic` is for you 😍.
35+
If you develop DRF APIs and rely on pydantic for data validation/(de)serialization ,
36+
then `drf-pydantic` is for you 😍.
3637

3738
# Installation
3839

@@ -55,23 +56,36 @@ class MyModel(BaseModel):
5556
addresses: list[str]
5657
```
5758

59+
`MyModel.drf_serializer` would be equvalent to the following DRF Serializer class:
60+
61+
```python
62+
class MyModelSerializer:
63+
name = CharField(allow_null=False, required=True)
64+
addresses = ListField(
65+
allow_empty=True,
66+
allow_null=False,
67+
child=CharField(allow_null=False),
68+
required=True,
69+
)
70+
```
71+
5872
Whenever you need a DRF serializer you can get it from the model like this:
5973

6074
```python
61-
MyModel.drf_serializer
75+
my_value = MyModel.drf_serializer(data={"name": "Van", addresses: ["Gym"]})
76+
my_value.is_valid(raise_exception=True)
6277
```
6378

6479
> ℹ️ **INFO**<br>
6580
> Models created using `drf_pydantic` are fully idenditcal to those created by
66-
> `pydantic`. The only change is the addition of the `drf_serializer` attribute
67-
> during class creation (not instance).
81+
> `pydantic`. The only change is the addition of the `drf_serializer` attribute.
6882
6983
## Existing Models
7084

71-
If you have an existing code base and you would like to use the `drf_serializer`
72-
attribute to only specific models, then great news 🥳 - you can easily extend
73-
your existign `pydantic` models by adding `drf_pydantic.BaseModel` to the list
74-
of parent classes.
85+
If you have an existing code base and you would like to add the `drf_serializer`
86+
attribute only to some of your models, then I have great news 🥳 - you can easily
87+
extend your existing `pydantic` models by adding `drf_pydantic.BaseModel` to the list
88+
of parent classes of the model you want to extend.
7589

7690
Your existing pydantic models:
7791

@@ -108,7 +122,7 @@ Dog.drf_serializer
108122

109123
If you have nested models and you want to generate serializer only from one of them,
110124
you don't have to update all models - only update the model you need, `drf_pydantic`
111-
will generate serializers for all normal nested `pydantic` models for free 🐱‍👤.
125+
will generate serializers for all normal nested `pydantic` models for free 🥷.
112126

113127
```python
114128
from drf_pydantic import BaseModel as DRFBaseModel
@@ -132,4 +146,3 @@ Block.drf_serializer
132146

133147
- Add support for custom field types (both for pydantic and DRF)
134148
- Add option to create custom serializer for complex models
135-
- Add support for constraints (max, min, regex, etc.)

0 commit comments

Comments
 (0)