VuedaSerializer
Overview
Standard serializer base for all VUEDA models. Combines extra-field rejection, flex-fields expansion, writable nested relations, and an available_actions field that exposes permitted actions for the current user.
Meta
Source
server/vueda/core/serializers/__init__.py:1092
build_standard_field
Accept null for a file or image column that the model marks blank=True.
DRF only allows null for a null=True column, and Django file columns are rarely nullable, so an optional file had no value that means "no file". Accepting null lets a form send its empty value, and lets a client clear a stored file. Django saves the cleared file as an empty name.
Signature
build_standard_field(self, field_name, model_field)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| self | yes | |||
| field_name | yes | |||
| model_field | yes |
Source
server/vueda/core/serializers/__init__.py:1079
create
We have a bit of extra checking around this in order to provide descriptive messages when something goes wrong, but this method is essentially just:
return ExampleModel.objects.create(**validated_data)
If there are many to many fields present on the instance then they cannot be set until the model is instantiated, in which case the implementation is like so:
example_relationship = validated_data.pop('example_relationship')
instance = ExampleModel.objects.create(**validated_data)
instance.example_relationship = example_relationship
return instance
The default implementation also does not handle nested relationships. If you want to support writable nested relationships you'll need to write an explicit .create() method.
Signature
create(self, validated_data)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| self | yes | |||
| validated_data | yes |
Source
server/vueda/core/serializers/__init__.py:1035
get_field_model_info
Customization hook for the model_fields metadata the /info/ meta-API returns for this serializer. Receives the generated field metadata dict (keyed by field name) and must return a dict in the same shape; override to correct or add entries, such as the real type of a SerializerMethodField. The default implementation applies field_display_choices.
Signature
get_field_model_info(self, fields)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| self | yes | |||
| fields | yes |
Source
server/vueda/core/serializers/__init__.py:1008
get_fields
Return fields after applying constructor-sourced flex-fields options.
Signature
get_fields(self)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| self | yes |
Source
server/vueda/core/serializers/__init__.py:1000
get_warnings
Return advisory warnings for the current create/update as a mapping of {field_name: [messages], "non_field_errors": [messages]}. An empty mapping means no warnings.
Override to surface non-blocking concerns the user should confirm before the write commits (for example, "this will deactivate the last administrator"). This is called by the viewset after validation succeeds, so self.validated_data is populated and self.instance holds the current (pre-save) instance on updates. It must not raise: blocking conditions belong in validate/VuedaValidationError (which return 400), whereas warnings gate the save behind an explicit client confirmation (see WarningConfirmationMixin).
Signature
get_warnings(self)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| self | yes |
Source
server/vueda/core/serializers/__init__.py:1041
to_representation
Drops available_actions from self.fields before rendering when a client hasn't named it through ?f=, rather than computing it and discarding the result afterward. Unlike an ordinary field, available_actions is not part of the default response -- a client must ask for it explicitly -- and computing it runs a permission check per CRUD action and per extra action, so a response that will drop it anyway must not pay for it.
Signature
to_representation(self, instance)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| self | yes | |||
| instance | yes |
Source
server/vueda/core/serializers/__init__.py:1056
update
Signature
update(self, instance, validated_data)
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| self | yes | |||
| instance | yes | |||
| validated_data | yes |
Source
server/vueda/core/serializers/__init__.py:1038
available_actions
formatted_name
object_revision
serializer_field_mapping
Source
server/vueda/core/serializers/__init__.py:982