Serializers
Serializers within Centurion ERP are responsible for arranging the data for presentation to the user as well as sanitization and validation for incoming user data. As Centurion ERP is an API based application the serializer is crucial to its operation
Introduction
Our Serializers are broken down into three different types, they are:
-
Base Serializer
-
Model Serializer
-
View Serializer
Base Serializer
The base serializer is a read-only serializer that returns only minimal data about a model, that being: id, display name and url. Even though this serializer only returns minimal data, it's crucial data that the interfact uses for linking data between models.
Model Serializer
The Model serializer is the write capable serializer and is used for both add and update actions. This serializer is also responsible for the sanitization and validation of user provided data.
Tip
Models can also be responsible for validating data as well. Ensure that you dont add to your serializer validation logic that the model is responsible for.
View Serializer
The View serializer as the name implies is for viewing a model. Unlike the model serializer, this serializer will return all linked fields (model related fields) using that models base serializer. This serializer is also used to return an object as part of a CRUD operation.
Creating a Serializer
All serializers are placed within a module under a directory called serializers
. For clarification serializers are named according to its models name (<model>._meta.model_name
). for sub-models this name is prefixed with <base model>._meta.model_name_
.
Danger
Failing to use this naming schema will caused a crash as the serializers cant be located by the "loader"
Requirements
When creating a serializer, the following requirements must be met:
-
inherits from:
-
Thier preceeding serializer. i.e.
View
inheritsModel
which inheritsBase
-
View serializer,
api.serializers.common.CommonModelSerializer
-
-
Follows file naming as described above
-
Base
serializer must return fieldsid
,display_name
andurl
, with url being the models url -
View
serializer must return a dict field called_urls
which contains links to the models core features, including_self
Available Serializers
With the exception of Centurion ERP models, the following additional serializers are available:
-
User
centurion.serializers.content_type
-
User
centurion.serializers.permission
-
User
centurion.serializers.user
About:
This page forms part of our Project Centurion ERP.
Page Metadata
Version: ToDo: place files short git commit hereDate Created: 2025-05-27
Date Edited: 2025-05-26
Contribution:
Would You like to contribute to our Centurion ERP project? You can assist in the following ways:
- Edit This Page If there is a mistake or a way you can improve it.
- Add a Page to the Manual if you would like to add an item to our manual
- Raise an Issue if there is something about this page you would like to improve, and git is unfamiliar to you.
ToDo: Add the page list of contributors