Skip to content

Commit

Permalink
Update README, bump to 0.3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
surenkov committed Apr 23, 2024
1 parent 3c8b4ff commit afa1a5c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MyModel(models.Model):
raw_uids: set[UUID] = SchemaField()

...

model = MyModel(
foo_field={"count": "5"},
bar_list=[{}],
Expand Down Expand Up @@ -123,23 +123,23 @@ assert form.cleaned_data["field"] == Foo(slug="asdf")
`django_pydantic_field` also supports auto-generated fields for `ModelForm` and `modelform_factory`:

``` python
class FooModelForm(forms.ModelForm):
class MyModelForm(forms.ModelForm):
class Meta:
model = Foo
fields = ["field"]
model = MyModel
fields = ["foo_field"]

form = FooModelForm(data={"field": '{"slug": "asdf"}'})
form = MyModelForm(data={"foo_field": '{"count": 5}'})
assert form.is_valid()
assert form.cleaned_data["field"] == Foo(slug="asdf")
assert form.cleaned_data["foo_field"] == Foo(count=5)

...

# ModelForm factory support
AnotherFooModelForm = modelform_factory(Foo, fields=["field"])
form = AnotherFooModelForm(data={"field": '{"slug": "bar_baz"}'})
AnotherModelForm = modelform_factory(MyModel, fields=["foo_field"])
form = AnotherModelForm(data={"foo_field": '{"count": 5}'})

assert form.is_valid()
assert form.cleaned_data["field"] == Foo(slug="bar_baz")
assert form.cleaned_data["foo_field"] == Foo(count=5)
```

Note, that forward references would be resolved until field is being bound to the form instance.
Expand All @@ -165,8 +165,8 @@ from django_jsonform.widgets import JSONFormWidget
# NOTE: Importing direct field class instead of `SchemaField` wrapper.
from django_pydantic_field.v2.fields import PydanticSchemaField

@admin.site.register(SchemaModel)
class SchemaModelAdmin(admin.ModelAdmin):
@admin.site.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
formfield_overrides = {
PydanticSchemaField: {"widget": JSONFormWidget},
}
Expand Down Expand Up @@ -241,4 +241,3 @@ To get `django-pydantic-field` up and running in development mode:

* [Churkin Oleg](https://gist.github.com/Bahus/98a9848b1f8e2dcd986bf9f05dbf9c65) for his Gist as a source of inspiration;
* Boutique Air Flight Operations platform as a test ground;

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "django-pydantic-field"
version = "0.3.7"
version = "0.3.8"
description = "Django JSONField with Pydantic models as a Schema"
readme = "README.md"
license = { file = "LICENSE" }
Expand Down

0 comments on commit afa1a5c

Please sign in to comment.