@@ -63,7 +63,6 @@ class CreateUserSchema(ModelSchema):
6363## ` from_orm(cls, obj: Any) `
6464You can generate a schema instance from your django model instance
6565``` Python
66- from typings import Optional
6766from django.contrib.auth import get_user_model
6867from ninja_schema import ModelSchema, model_validator
6968
@@ -90,15 +89,14 @@ print(schema.json(indent=2)
9089}
9190```
9291
93- # # `apply (self, model_instance, **kwargs)`
92+ # # `apply_to_model (self, model_instance, **kwargs)`
9493You can transfer data from your ModelSchema to Django Model instance using the `apply` function.
95- The `apply ` function uses Pydantic model `.dict` function, `dict ` function filtering that can be passed as `kwargs` to the `.apply` function.
94+ The `apply_to_model ` function uses Pydantic model `.dict` function, `dict ` function filtering that can be passed as `kwargs` to the `.apply` function.
9695
9796For more info, visit [Pydantic model export](https:// pydantic- docs.helpmanual.io/ usage/ exporting_models/ )
9897```Python
99- from typings import Optional
10098from django.contrib.auth import get_user_model
101- from ninja_schema import ModelSchema, model_validator
99+ from ninja_schema import ModelSchema
102100
103101UserModel = get_user_model()
104102new_user = UserModel.objects.create_user(
username = ' eadwin' ,
email = ' [email protected] ' ,
password = ' password' )
@@ -111,7 +109,7 @@ class UpdateUserSchema(ModelSchema):
111109 optional = [' username' ] # `username` is now optional
112110
113111schema = UpdateUserSchema(first_name = ' Emeka' , last_name = ' Okoro' )
114- schema.apply (new_user, exclude_none = True )
112+ schema.apply_to_model (new_user, exclude_none = True )
115113
116114assert new_user.first_name == ' Emeka' # True
117115assert new_user.username == ' eadwin' # True
@@ -269,4 +267,3 @@ print(UserSchema.schema())
269267 }
270268}
271269```
272-
0 commit comments