-
Notifications
You must be signed in to change notification settings - Fork 0
Properties
As you may already know, every SJD model has a set of properties. This properties inform the package about type of data you gonna put inside it.
Here you'll learn more about available properties that you can use inside your model.
Available types are those are available in JSON:
String
Integer
Float
Boolean
-
List
( orArray
) -
Object
( another JSON object )
You can access all of properties in one place like this:
from sjd import properties as props
Every property has a set of options that you can modify based on your case.
-
init
: Indicates if this property should be passed to model's__init__
function or not ( If there's any__init__
function defined ). -
json_property_name
: The property name inside json file. Defaults to attribute name. -
required
: Indicates if this property should always be available while serializing or deserializing object.
Here you can find a brief explanation about all properties and their use case.
For python str
fields.
Required Parameters: This method has no required parameter.
class Model(TEntity):
# ---- sniff ----
string_field = props.string()
# ---- sniff ----
For python int
fields.
Required Parameters: This method has no required parameter.
class Model(TEntity):
# ---- sniff ----
integer_field = props.integer()
# ---- sniff ----
For python float
fields. ( Why i named it like this then? )
Required Parameters: This method has no required parameter.
class Model(TEntity):
# ---- sniff ----
float_field = props.double()
# ---- sniff ----
For python bool
fields.
Required Parameters: This method has no required parameter.
class Model(TEntity):
# ---- sniff ----
bool_field = props.boolean()
# ---- sniff ----
For python list
fields. You can use this to store a list of any valid type.
Required Parameters:
-
of_typed
: You should pass the type of objects this field should store.
class Model(TEntity):
# ---- sniff ----
str_list_field = props.array(str)
other_models_field = props.array(OtherModel)
...
# ---- sniff ----