@ -20,17 +20,19 @@ Centurion ERP is a Django Application. We have added a lot of little tid bits th
|
||||
|
||||
- [Fields](./fields.md)
|
||||
|
||||
- [Forms](./forms.md)
|
||||
- ~~[Forms](./forms.md)~~ _Scheduled for removal_
|
||||
|
||||
- [Models](./models.md)
|
||||
|
||||
- [Entity](./core/entity.md)
|
||||
|
||||
- [Serializers](./serializers.md)
|
||||
|
||||
- [Templates](./templates.md)
|
||||
|
||||
- [Testing](./testing.md)
|
||||
|
||||
- [Views](./views.md)
|
||||
- ~~[Views](./views.md)~~ _Scheduled for removal_
|
||||
|
||||
|
||||
## Icons
|
||||
|
@ -125,7 +125,7 @@ All models must contain the core features, being:
|
||||
|
||||
## Validation Methods
|
||||
|
||||
Within All of our models including when they are created via an API serializer, the models [validators](https://docs.djangoproject.com/en/5.1/ref/models/instances/#validating-objects) are called. The models validators are responsible for ensuring that no data goes into the database that may create an inconsistancy.
|
||||
Within All of our models including when they are created via an [API serializer](./serializers.md), the models [validators](https://docs.djangoproject.com/en/5.1/ref/models/instances/#validating-objects) are called. The models validators are responsible for ensuring that no data goes into the database that may create an inconsistancy.
|
||||
|
||||
!!! example
|
||||
You have defined a model that has a user field that must always have a value. This model can be access via the API, in which the user field is auto-populated by object `request.user`. In the same token you have admin commands that uses this model.
|
||||
|
74
docs/projects/centurion_erp/development/serializers.md
Normal file
74
docs/projects/centurion_erp/development/serializers.md
Normal file
@ -0,0 +1,74 @@
|
||||
---
|
||||
title: Serializers
|
||||
description: Centurion ERP Serializers development documentation
|
||||
date: 2025-05-27
|
||||
template: project.html
|
||||
about: https://github.com/nofusscomputing/centurion_erp
|
||||
---
|
||||
|
||||
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](./models.md#validation-methods) 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` inherits `Model` which inherits `Base`
|
||||
|
||||
- View serializer, `api.serializers.common.CommonModelSerializer`
|
||||
|
||||
- Follows file naming as described [above](#creating-a-serializer)
|
||||
|
||||
- `Base` serializer must return fields `id`, `display_name` and `url`, with url being the models url
|
||||
|
||||
- `View` serializer must return a dict field called `_urls` which contains links to the models [core features](./models.md#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`
|
@ -127,6 +127,8 @@ nav:
|
||||
|
||||
- projects/centurion_erp/development/core/model_notes.md
|
||||
|
||||
- projects/centurion_erp/development/serializers.md
|
||||
|
||||
- projects/centurion_erp/development/itam/it_asset.md
|
||||
|
||||
- projects/centurion_erp/development/templates.md
|
||||
|
Reference in New Issue
Block a user