Skip to content

Commit 16fbf01

Browse files
committed
Update README.md
1 parent 4308345 commit 16fbf01

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

README.md

+23-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ An extended JSON field for Django and Django REST framework with validation supp
77

88
## Usage
99

10-
Install the package:
10+
### Installation
11+
12+
To install the package, run:
1113

1214
```text
1315
pip install django_custom_jsonfield
1416
```
1517

16-
Import `CustomJSONField` and define your `schema`, for example:
18+
### Defining a model field
19+
20+
Import CustomJSONField and define your schema. Here’s an example of how to use it in a model:
1721

1822
```python
1923
from django.db import models
@@ -37,8 +41,8 @@ Location(coordinates={"x": 45, "z": 45}) # ValidationError
3741

3842
```
3943

40-
## DRF Serializer
41-
Just like you use `CustomJSONField` in your models, you can use them in serializers:
44+
### DRF Serializers
45+
You can also use `CustomJSONField` in Django REST Framework serializers:
4246

4347
```python
4448
from rest_framework import serializers
@@ -49,4 +53,18 @@ class LocationSerializer(serializers.Serializer):
4953

5054
```
5155

52-
This package automatically comes with openapi extension for `drf-spectacular`.
56+
### OpenAPI Integration
57+
This package includes extension for `drf-spectacular`, allowing your API documentation
58+
to correctly display the expected JSON schema.
59+
60+
## Migrating existing data
61+
The `CustomJSONField` does not impose constraints on existing data.
62+
Therefore, you can change a field from default `JSONField` to `CustomJSONField` even if
63+
some rows violate the schema. However, it is recommended to follow these steps to
64+
sure a smooth transition:
65+
66+
1. **Create a new field**: add a new field of type `CustomJSONField` to your model.
67+
2. **Data migration**: Perform a data migration to copy the values from the old field to the new field, ensuring the data conforms to the schema.
68+
3. **Replace the old field**: Remove the old field and rename the new field to match the old field's name.
69+
70+
Following these steps will ensure that your data complies with the new schema.

0 commit comments

Comments
 (0)