Skip to content

Properties

immmdreza edited this page Jun 5, 2022 · 2 revisions

Learn about 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 ( or Array )
  • Object ( another JSON object )

Access

You can access all of properties in one place like this:

from sjd import properties as props

Options

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.

Explain

Here you can find a brief explanation about all properties and their use case.

props.string()

For python str fields.

Required Parameters: This method has no required parameter.

class Model(TEntity):
    # ---- sniff ----

    string_field = props.string()

    # ---- sniff ----

props.integer()

For python int fields.

Required Parameters: This method has no required parameter.

class Model(TEntity):
    # ---- sniff ----

    integer_field = props.integer()

    # ---- sniff ----

props.double()

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 ----

props.boolean()

For python bool fields.

Required Parameters: This method has no required parameter.

class Model(TEntity):
    # ---- sniff ----

    bool_field = props.boolean()

    # ---- sniff ----

props.array()

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 ----
Clone this wiki locally