Skip to content

Default Methods

Alexandre Costa edited this page Aug 18, 2024 · 3 revisions

Plugie can be set up using default methods for serializing and deserializing some of the most common types you will encounter in a plugin. Using Plugie CLI you create a plugie/custom_methods directory in your project directory, including a default.py file.

Differently from the Built-in Serializers-Deserializers Methods that are not to be overridden, the default methods can be customized to fit your needs.

Types

The default.py file includes methods for serializing (and deserializing) the following types:

  • str: strings
  • int: integer numbers
  • float: float numbers
  • bool: booleans
  • safetext: strings that can be displayed safely without further escaping in HTML
  • uuid: universally unique identifiers
  • decimal: fixed-point numbers
  • datetime: date and time
  • nonetype: None
  • cmsplugin: CMS plugins (only the plugin ID is needed)
  • _parent_related_field: a field that is related to the parent model. This method allows deserializing models that have a foreign key to the parent model.

You may notice that not every type requires a deserialize method, since Python is able to cast the serialized value to the correct type. When this is not possible, a deserialize method is needed to convert the serialized value to the correct type.