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:722
_reload_with_revision
Re-read a written row so its revision annotation is present.
A create or update returns the instance the write produced, which carries no annotation. The nested writable path reuses one serializer class for parent and child, so the view's queryset may belong to a different model than the instance; fall back to the instance's own manager in that case.
Signature
_reload_with_revision(self, instance)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| instance | yes |
Source
server/vueda/core/serializers/__init__.py:665
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 | Description |
|---|---|---|---|
| self | yes | ||
| validated_data | yes |
Source
server/vueda/core/serializers/__init__.py:684
get_fields
Return the dict of field names -> field instances that should be used for self.fields when instantiating the serializer.
Signature
get_fields(self)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes |
Source
server/vueda/core/serializers/__init__.py:657
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 | Description |
|---|---|---|---|
| self | yes |
Source
server/vueda/core/serializers/__init__.py:690
to_representation
?f=/?om= (_flex_options_rep_only, sourced from query params) narrow the representation only. Applying them here, rather than in to_internal_value, keeps a write validating against the serializer's full field set while still narrowing the response a write returns, since to_representation runs after save().
fields=/omit= passed as serializer kwargs (_flex_options_base) are a different entry point: get_fields() applies them before either to_internal_value or to_representation runs, so they narrow validation and representation alike. That is unchanged and deliberate -- a caller constructing a serializer with explicit kwargs is opting in to restricting both directions, unlike a client shaping a response with a query parameter.
Delegates the view-bound check and the actual application to ensure_flex_fields_applied, the same helper a caller like VuedaViewSet.get_queryset uses to resolve .fields before an instance is ever serialized (for prefetch planning). Both call sites must agree on when application is safe and on the _flex_fields_rep_applied double-application guard, so that logic lives in one place rather than two copies that could drift.
Signature
to_representation(self, instance)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| instance | yes |
Source
server/vueda/core/serializers/__init__.py:705
update
Signature
update(self, instance, validated_data)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| instance | yes | ||
| validated_data | yes |
Source
server/vueda/core/serializers/__init__.py:687
_declared_fields
available_actions
formatted_name
object_revision
serializer_field_mapping
Source
server/vueda/core/serializers/__init__.py:640