Serializers#
Contains the main Serializers for the FMA Django API.
- class fma_django_api.v1.serializers.ClientSerializer(*args, **kwargs)#
Bases:
ModelSerializer
The serializer for clients associated with a model.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
- bind(field_name, parent)#
Initializes the field name and parent for the field instance. Called when a field is added to the parent serializer instance.
- build_field(field_name, info, model_class, nested_depth)#
Return a two tuple of (cls, kwargs) to build a serializer field with.
- build_nested_field(field_name, relation_info, nested_depth)#
Create nested fields for forward and reverse relationships.
- build_property_field(field_name, model_class)#
Create a read only field for model methods and properties.
- build_relational_field(field_name, relation_info)#
Create fields for forward and reverse relationships.
- build_standard_field(field_name, model_field)#
Create regular model fields.
- build_unknown_field(field_name, model_class)#
Raise an error on any unknown fields.
- build_url_field(field_name, model_class)#
Create a field representing the object’s own URL.
- property context#
Returns the context as passed to the root serializer on initialization.
- create(validated_data)#
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.
- property data#
- default_empty_html#
alias of
empty
- default_error_messages = {'invalid': 'Invalid data. Expected a dictionary, but got {datatype}.'}#
- default_validators = []#
- property errors#
- fail(key, **kwargs)#
A helper method that simply raises a validation error.
- fields#
field_instance}.
- Type:
A dictionary of {field_name
- get_attribute(instance)#
Given the outgoing object instance, return the primitive value that should be used for this field.
- get_default()#
Return the default value to use when validating data if no input is provided for this field.
If a default has not been set for this field then this will simply raise SkipField, indicating that no value should be set in the validated data for this field.
- get_default_field_names(declared_fields, model_info)#
Return the default list of field names that will be used if the Meta.fields option is not specified.
- get_extra_kwargs()#
Return a dictionary mapping field names to a dictionary of additional keyword arguments.
- get_field_names(declared_fields, info)#
Returns the list of all field names that should be created when instantiating this serializer class. This is based on the default set of fields, but also takes into account the Meta.fields or Meta.exclude options if they have been specified.
- get_fields()#
Return the dict of field names -> field instances that should be used for self.fields when instantiating the serializer.
- get_initial()#
Return a value to use when the field is being returned as a primitive value, without any object instance.
- get_unique_for_date_validators()#
Determine a default set of validators for the following constraints:
unique_for_date
unique_for_month
unique_for_year
- get_unique_together_validators()#
Determine a default set of validators for any unique_together constraints.
- get_uniqueness_extra_kwargs(field_names, declared_fields, extra_kwargs)#
Return any additional field options that need to be included as a result of uniqueness constraints on the model. This is returned as a two-tuple of:
(‘dict of updated extra kwargs’, ‘mapping of hidden fields’)
- get_validators()#
Determine the set of validators to use when instantiating serializer.
- get_value(dictionary)#
Given the incoming primitive data, return the value for this field that should be validated and transformed to a native value.
- include_extra_kwargs(kwargs, extra_kwargs)#
Include any ‘extra_kwargs’ that have been included for this field, possibly removing any incompatible existing keyword arguments.
- initial = None#
- is_valid(raise_exception=False)#
- classmethod many_init(*args, **kwargs)#
This method implements the creation of a ListSerializer parent class when many=True is used. You can customize it if you need to control which keyword arguments are passed to the parent, and which are passed to the child.
Note that we’re over-cautious in passing most arguments to both parent and child classes in order to try to cover the general case. If you’re overriding this method you’ll probably want something much simpler, eg:
@classmethod def many_init(cls, *args, **kwargs):
- property root#
Returns the top-level serializer for this field.
- run_validation(data=<class 'rest_framework.fields.empty'>)#
We override the default run_validation, because the validation performed by validators and the .validate() method should be coerced into an error dictionary with a ‘non_fields_error’ key.
- run_validators(value)#
Add read_only fields with defaults to value before running validators.
- save(**kwargs)#
- serializer_choice_field#
alias of
ChoiceField
- serializer_field_mapping = {<class 'django.db.models.fields.AutoField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.BigIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.BooleanField'>: <class 'rest_framework.fields.BooleanField'>, <class 'django.db.models.fields.CharField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.CommaSeparatedIntegerField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.DateField'>: <class 'rest_framework.fields.DateField'>, <class 'django.db.models.fields.DateTimeField'>: <class 'rest_framework.fields.DateTimeField'>, <class 'django.db.models.fields.DecimalField'>: <class 'rest_framework.fields.DecimalField'>, <class 'django.db.models.fields.DurationField'>: <class 'rest_framework.fields.DurationField'>, <class 'django.db.models.fields.EmailField'>: <class 'rest_framework.fields.EmailField'>, <class 'django.db.models.fields.Field'>: <class 'rest_framework.fields.ModelField'>, <class 'django.db.models.fields.files.FileField'>: <class 'rest_framework.fields.FileField'>, <class 'django.db.models.fields.FloatField'>: <class 'rest_framework.fields.FloatField'>, <class 'django.db.models.fields.files.ImageField'>: <class 'rest_framework.fields.ImageField'>, <class 'django.db.models.fields.IntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.NullBooleanField'>: <class 'rest_framework.fields.BooleanField'>, <class 'django.db.models.fields.PositiveIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.PositiveSmallIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.SlugField'>: <class 'rest_framework.fields.SlugField'>, <class 'django.db.models.fields.SmallIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.TextField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.TimeField'>: <class 'rest_framework.fields.TimeField'>, <class 'django.db.models.fields.URLField'>: <class 'rest_framework.fields.URLField'>, <class 'django.db.models.fields.UUIDField'>: <class 'rest_framework.fields.UUIDField'>, <class 'django.db.models.fields.GenericIPAddressField'>: <class 'rest_framework.fields.IPAddressField'>, <class 'django.db.models.fields.FilePathField'>: <class 'rest_framework.fields.FilePathField'>, <class 'django.db.models.fields.json.JSONField'>: <class 'rest_framework.fields.JSONField'>, <class 'django.contrib.postgres.fields.hstore.HStoreField'>: <class 'rest_framework.fields.HStoreField'>, <class 'django.contrib.postgres.fields.array.ArrayField'>: <class 'rest_framework.fields.ListField'>, <class 'django.contrib.postgres.fields.jsonb.JSONField'>: <class 'rest_framework.fields.JSONField'>}#
alias of
PrimaryKeyRelatedField
alias of
SlugRelatedField
- serializer_url_field#
alias of
HyperlinkedIdentityField
- to_internal_value(data)#
Dict of native values <- Dict of primitive datatypes.
- to_representation(instance)#
Object instance -> Dict of primitive datatypes.
- update(instance, validated_data)#
- url_field_name = None#
- validate(attrs)#
- validate_empty_values(data)#
Validate empty values, and either:
Raise ValidationError, indicating invalid data.
Raise SkipField, indicating that the field should be ignored.
Return (True, data), indicating an empty value that should be returned without any further validation being applied.
Return (False, data), indicating a non-empty value, that should have validation applied as normal.
- property validated_data#
- property validators#
- class fma_django_api.v1.serializers.ModelArtifactSerializer(*args, **kwargs)#
Bases:
ModelSerializer
The serializer for Model Artifacts.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
- class Meta#
Bases:
object
- model#
alias of
ModelArtifact
- fields = '__all__'#
- read_only_fields = ['federated_model']#
- bind(field_name, parent)#
Initializes the field name and parent for the field instance. Called when a field is added to the parent serializer instance.
- build_field(field_name, info, model_class, nested_depth)#
Return a two tuple of (cls, kwargs) to build a serializer field with.
- build_nested_field(field_name, relation_info, nested_depth)#
Create nested fields for forward and reverse relationships.
- build_property_field(field_name, model_class)#
Create a read only field for model methods and properties.
- build_relational_field(field_name, relation_info)#
Create fields for forward and reverse relationships.
- build_standard_field(field_name, model_field)#
Create regular model fields.
- build_unknown_field(field_name, model_class)#
Raise an error on any unknown fields.
- build_url_field(field_name, model_class)#
Create a field representing the object’s own URL.
- property context#
Returns the context as passed to the root serializer on initialization.
- create(validated_data)#
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.
- property data#
- default_empty_html#
alias of
empty
- default_error_messages = {'invalid': 'Invalid data. Expected a dictionary, but got {datatype}.'}#
- default_validators = []#
- property errors#
- fail(key, **kwargs)#
A helper method that simply raises a validation error.
- fields#
field_instance}.
- Type:
A dictionary of {field_name
- get_attribute(instance)#
Given the outgoing object instance, return the primitive value that should be used for this field.
- get_default()#
Return the default value to use when validating data if no input is provided for this field.
If a default has not been set for this field then this will simply raise SkipField, indicating that no value should be set in the validated data for this field.
- get_default_field_names(declared_fields, model_info)#
Return the default list of field names that will be used if the Meta.fields option is not specified.
- get_extra_kwargs()#
Return a dictionary mapping field names to a dictionary of additional keyword arguments.
- get_field_names(declared_fields, info)#
Returns the list of all field names that should be created when instantiating this serializer class. This is based on the default set of fields, but also takes into account the Meta.fields or Meta.exclude options if they have been specified.
- get_fields()#
Return the dict of field names -> field instances that should be used for self.fields when instantiating the serializer.
- get_initial()#
Return a value to use when the field is being returned as a primitive value, without any object instance.
- get_unique_for_date_validators()#
Determine a default set of validators for the following constraints:
unique_for_date
unique_for_month
unique_for_year
- get_unique_together_validators()#
Determine a default set of validators for any unique_together constraints.
- get_uniqueness_extra_kwargs(field_names, declared_fields, extra_kwargs)#
Return any additional field options that need to be included as a result of uniqueness constraints on the model. This is returned as a two-tuple of:
(‘dict of updated extra kwargs’, ‘mapping of hidden fields’)
- get_validators()#
Determine the set of validators to use when instantiating serializer.
- get_value(dictionary)#
Given the incoming primitive data, return the value for this field that should be validated and transformed to a native value.
- include_extra_kwargs(kwargs, extra_kwargs)#
Include any ‘extra_kwargs’ that have been included for this field, possibly removing any incompatible existing keyword arguments.
- initial = None#
- is_valid(raise_exception=False)#
- classmethod many_init(*args, **kwargs)#
This method implements the creation of a ListSerializer parent class when many=True is used. You can customize it if you need to control which keyword arguments are passed to the parent, and which are passed to the child.
Note that we’re over-cautious in passing most arguments to both parent and child classes in order to try to cover the general case. If you’re overriding this method you’ll probably want something much simpler, eg:
@classmethod def many_init(cls, *args, **kwargs):
- property root#
Returns the top-level serializer for this field.
- run_validation(data=<class 'rest_framework.fields.empty'>)#
We override the default run_validation, because the validation performed by validators and the .validate() method should be coerced into an error dictionary with a ‘non_fields_error’ key.
- run_validators(value)#
Add read_only fields with defaults to value before running validators.
- save(**kwargs)#
- serializer_choice_field#
alias of
ChoiceField
- serializer_field_mapping = {<class 'django.db.models.fields.AutoField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.BigIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.BooleanField'>: <class 'rest_framework.fields.BooleanField'>, <class 'django.db.models.fields.CharField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.CommaSeparatedIntegerField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.DateField'>: <class 'rest_framework.fields.DateField'>, <class 'django.db.models.fields.DateTimeField'>: <class 'rest_framework.fields.DateTimeField'>, <class 'django.db.models.fields.DecimalField'>: <class 'rest_framework.fields.DecimalField'>, <class 'django.db.models.fields.DurationField'>: <class 'rest_framework.fields.DurationField'>, <class 'django.db.models.fields.EmailField'>: <class 'rest_framework.fields.EmailField'>, <class 'django.db.models.fields.Field'>: <class 'rest_framework.fields.ModelField'>, <class 'django.db.models.fields.files.FileField'>: <class 'rest_framework.fields.FileField'>, <class 'django.db.models.fields.FloatField'>: <class 'rest_framework.fields.FloatField'>, <class 'django.db.models.fields.files.ImageField'>: <class 'rest_framework.fields.ImageField'>, <class 'django.db.models.fields.IntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.NullBooleanField'>: <class 'rest_framework.fields.BooleanField'>, <class 'django.db.models.fields.PositiveIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.PositiveSmallIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.SlugField'>: <class 'rest_framework.fields.SlugField'>, <class 'django.db.models.fields.SmallIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.TextField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.TimeField'>: <class 'rest_framework.fields.TimeField'>, <class 'django.db.models.fields.URLField'>: <class 'rest_framework.fields.URLField'>, <class 'django.db.models.fields.UUIDField'>: <class 'rest_framework.fields.UUIDField'>, <class 'django.db.models.fields.GenericIPAddressField'>: <class 'rest_framework.fields.IPAddressField'>, <class 'django.db.models.fields.FilePathField'>: <class 'rest_framework.fields.FilePathField'>, <class 'django.db.models.fields.json.JSONField'>: <class 'rest_framework.fields.JSONField'>, <class 'django.contrib.postgres.fields.hstore.HStoreField'>: <class 'rest_framework.fields.HStoreField'>, <class 'django.contrib.postgres.fields.array.ArrayField'>: <class 'rest_framework.fields.ListField'>, <class 'django.contrib.postgres.fields.jsonb.JSONField'>: <class 'rest_framework.fields.JSONField'>}#
alias of
PrimaryKeyRelatedField
alias of
SlugRelatedField
- serializer_url_field#
alias of
HyperlinkedIdentityField
- to_internal_value(data)#
Dict of native values <- Dict of primitive datatypes.
- to_representation(instance)#
Object instance -> Dict of primitive datatypes.
- update(instance, validated_data)#
- url_field_name = None#
- validate(attrs)#
- validate_empty_values(data)#
Validate empty values, and either:
Raise ValidationError, indicating invalid data.
Raise SkipField, indicating that the field should be ignored.
Return (True, data), indicating an empty value that should be returned without any further validation being applied.
Return (False, data), indicating a non-empty value, that should have validation applied as normal.
- property validated_data#
- property validators#
- class fma_django_api.v1.serializers.FederatedModelSerializer(*args, **kwargs)#
Bases:
ModelSerializer
The serializer for federated models.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
- class Meta#
Bases:
object
- model#
alias of
FederatedModel
- read_only_fields = ['current_artifact']#
- exclude = ('scheduler',)#
- extra_fields = 'allow_aggregation'#
- update(instance, validated_data)#
Overloads update to use the allow_aggregation field.
- Parameters:
instance (fma_django.models.FederatedModel) – the federated model which is being updated
validated_data (dict) – metadata where allow_aggregation status is found
- Returns:
updated federated model
- Return type:
- bind(field_name, parent)#
Initializes the field name and parent for the field instance. Called when a field is added to the parent serializer instance.
- build_field(field_name, info, model_class, nested_depth)#
Return a two tuple of (cls, kwargs) to build a serializer field with.
- build_nested_field(field_name, relation_info, nested_depth)#
Create nested fields for forward and reverse relationships.
- build_property_field(field_name, model_class)#
Create a read only field for model methods and properties.
- build_relational_field(field_name, relation_info)#
Create fields for forward and reverse relationships.
- build_standard_field(field_name, model_field)#
Create regular model fields.
- build_unknown_field(field_name, model_class)#
Raise an error on any unknown fields.
- build_url_field(field_name, model_class)#
Create a field representing the object’s own URL.
- property context#
Returns the context as passed to the root serializer on initialization.
- create(validated_data)#
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.
- property data#
- default_empty_html#
alias of
empty
- default_error_messages = {'invalid': 'Invalid data. Expected a dictionary, but got {datatype}.'}#
- default_validators = []#
- property errors#
- fail(key, **kwargs)#
A helper method that simply raises a validation error.
- fields#
field_instance}.
- Type:
A dictionary of {field_name
- get_attribute(instance)#
Given the outgoing object instance, return the primitive value that should be used for this field.
- get_default()#
Return the default value to use when validating data if no input is provided for this field.
If a default has not been set for this field then this will simply raise SkipField, indicating that no value should be set in the validated data for this field.
- get_default_field_names(declared_fields, model_info)#
Return the default list of field names that will be used if the Meta.fields option is not specified.
- get_extra_kwargs()#
Return a dictionary mapping field names to a dictionary of additional keyword arguments.
- get_field_names(declared_fields, info)#
Returns the list of all field names that should be created when instantiating this serializer class. This is based on the default set of fields, but also takes into account the Meta.fields or Meta.exclude options if they have been specified.
- get_fields()#
Return the dict of field names -> field instances that should be used for self.fields when instantiating the serializer.
- get_initial()#
Return a value to use when the field is being returned as a primitive value, without any object instance.
- get_unique_for_date_validators()#
Determine a default set of validators for the following constraints:
unique_for_date
unique_for_month
unique_for_year
- get_unique_together_validators()#
Determine a default set of validators for any unique_together constraints.
- get_uniqueness_extra_kwargs(field_names, declared_fields, extra_kwargs)#
Return any additional field options that need to be included as a result of uniqueness constraints on the model. This is returned as a two-tuple of:
(‘dict of updated extra kwargs’, ‘mapping of hidden fields’)
- get_validators()#
Determine the set of validators to use when instantiating serializer.
- get_value(dictionary)#
Given the incoming primitive data, return the value for this field that should be validated and transformed to a native value.
- include_extra_kwargs(kwargs, extra_kwargs)#
Include any ‘extra_kwargs’ that have been included for this field, possibly removing any incompatible existing keyword arguments.
- initial = None#
- is_valid(raise_exception=False)#
- classmethod many_init(*args, **kwargs)#
This method implements the creation of a ListSerializer parent class when many=True is used. You can customize it if you need to control which keyword arguments are passed to the parent, and which are passed to the child.
Note that we’re over-cautious in passing most arguments to both parent and child classes in order to try to cover the general case. If you’re overriding this method you’ll probably want something much simpler, eg:
@classmethod def many_init(cls, *args, **kwargs):
- property root#
Returns the top-level serializer for this field.
- run_validation(data=<class 'rest_framework.fields.empty'>)#
We override the default run_validation, because the validation performed by validators and the .validate() method should be coerced into an error dictionary with a ‘non_fields_error’ key.
- run_validators(value)#
Add read_only fields with defaults to value before running validators.
- save(**kwargs)#
- serializer_choice_field#
alias of
ChoiceField
- serializer_field_mapping = {<class 'django.db.models.fields.AutoField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.BigIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.BooleanField'>: <class 'rest_framework.fields.BooleanField'>, <class 'django.db.models.fields.CharField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.CommaSeparatedIntegerField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.DateField'>: <class 'rest_framework.fields.DateField'>, <class 'django.db.models.fields.DateTimeField'>: <class 'rest_framework.fields.DateTimeField'>, <class 'django.db.models.fields.DecimalField'>: <class 'rest_framework.fields.DecimalField'>, <class 'django.db.models.fields.DurationField'>: <class 'rest_framework.fields.DurationField'>, <class 'django.db.models.fields.EmailField'>: <class 'rest_framework.fields.EmailField'>, <class 'django.db.models.fields.Field'>: <class 'rest_framework.fields.ModelField'>, <class 'django.db.models.fields.files.FileField'>: <class 'rest_framework.fields.FileField'>, <class 'django.db.models.fields.FloatField'>: <class 'rest_framework.fields.FloatField'>, <class 'django.db.models.fields.files.ImageField'>: <class 'rest_framework.fields.ImageField'>, <class 'django.db.models.fields.IntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.NullBooleanField'>: <class 'rest_framework.fields.BooleanField'>, <class 'django.db.models.fields.PositiveIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.PositiveSmallIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.SlugField'>: <class 'rest_framework.fields.SlugField'>, <class 'django.db.models.fields.SmallIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.TextField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.TimeField'>: <class 'rest_framework.fields.TimeField'>, <class 'django.db.models.fields.URLField'>: <class 'rest_framework.fields.URLField'>, <class 'django.db.models.fields.UUIDField'>: <class 'rest_framework.fields.UUIDField'>, <class 'django.db.models.fields.GenericIPAddressField'>: <class 'rest_framework.fields.IPAddressField'>, <class 'django.db.models.fields.FilePathField'>: <class 'rest_framework.fields.FilePathField'>, <class 'django.db.models.fields.json.JSONField'>: <class 'rest_framework.fields.JSONField'>, <class 'django.contrib.postgres.fields.hstore.HStoreField'>: <class 'rest_framework.fields.HStoreField'>, <class 'django.contrib.postgres.fields.array.ArrayField'>: <class 'rest_framework.fields.ListField'>, <class 'django.contrib.postgres.fields.jsonb.JSONField'>: <class 'rest_framework.fields.JSONField'>}#
alias of
PrimaryKeyRelatedField
alias of
SlugRelatedField
- serializer_url_field#
alias of
HyperlinkedIdentityField
- to_internal_value(data)#
Dict of native values <- Dict of primitive datatypes.
- to_representation(instance)#
Object instance -> Dict of primitive datatypes.
- url_field_name = None#
- validate(attrs)#
- validate_empty_values(data)#
Validate empty values, and either:
Raise ValidationError, indicating invalid data.
Raise SkipField, indicating that the field should be ignored.
Return (True, data), indicating an empty value that should be returned without any further validation being applied.
Return (False, data), indicating a non-empty value, that should have validation applied as normal.
- property validated_data#
- property validators#
- class fma_django_api.v1.serializers.CreateFederatedModelSerializer(*args, **kwargs)#
Bases:
FederatedModelSerializer
The serializer for creating a federated model.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
- class Meta#
Bases:
Meta
- exclude = ('scheduler',)#
- extra_fields = 'allow_aggregation'#
- model#
alias of
FederatedModel
- read_only_fields = ['current_artifact']#
- create(validated_data)#
Creates a federated model object from validated model data.
- Parameters:
validated_data (Any) – A validated federated model object
- Returns:
A new or updated federated model
- Return type:
- bind(field_name, parent)#
Initializes the field name and parent for the field instance. Called when a field is added to the parent serializer instance.
- build_field(field_name, info, model_class, nested_depth)#
Return a two tuple of (cls, kwargs) to build a serializer field with.
- build_nested_field(field_name, relation_info, nested_depth)#
Create nested fields for forward and reverse relationships.
- build_property_field(field_name, model_class)#
Create a read only field for model methods and properties.
- build_relational_field(field_name, relation_info)#
Create fields for forward and reverse relationships.
- build_standard_field(field_name, model_field)#
Create regular model fields.
- build_unknown_field(field_name, model_class)#
Raise an error on any unknown fields.
- build_url_field(field_name, model_class)#
Create a field representing the object’s own URL.
- property context#
Returns the context as passed to the root serializer on initialization.
- property data#
- default_empty_html#
alias of
empty
- default_error_messages = {'invalid': 'Invalid data. Expected a dictionary, but got {datatype}.'}#
- default_validators = []#
- property errors#
- fail(key, **kwargs)#
A helper method that simply raises a validation error.
- fields#
field_instance}.
- Type:
A dictionary of {field_name
- get_attribute(instance)#
Given the outgoing object instance, return the primitive value that should be used for this field.
- get_default()#
Return the default value to use when validating data if no input is provided for this field.
If a default has not been set for this field then this will simply raise SkipField, indicating that no value should be set in the validated data for this field.
- get_default_field_names(declared_fields, model_info)#
Return the default list of field names that will be used if the Meta.fields option is not specified.
- get_extra_kwargs()#
Return a dictionary mapping field names to a dictionary of additional keyword arguments.
- get_field_names(declared_fields, info)#
Returns the list of all field names that should be created when instantiating this serializer class. This is based on the default set of fields, but also takes into account the Meta.fields or Meta.exclude options if they have been specified.
- get_fields()#
Return the dict of field names -> field instances that should be used for self.fields when instantiating the serializer.
- get_initial()#
Return a value to use when the field is being returned as a primitive value, without any object instance.
- get_unique_for_date_validators()#
Determine a default set of validators for the following constraints:
unique_for_date
unique_for_month
unique_for_year
- get_unique_together_validators()#
Determine a default set of validators for any unique_together constraints.
- get_uniqueness_extra_kwargs(field_names, declared_fields, extra_kwargs)#
Return any additional field options that need to be included as a result of uniqueness constraints on the model. This is returned as a two-tuple of:
(‘dict of updated extra kwargs’, ‘mapping of hidden fields’)
- get_validators()#
Determine the set of validators to use when instantiating serializer.
- get_value(dictionary)#
Given the incoming primitive data, return the value for this field that should be validated and transformed to a native value.
- include_extra_kwargs(kwargs, extra_kwargs)#
Include any ‘extra_kwargs’ that have been included for this field, possibly removing any incompatible existing keyword arguments.
- initial = None#
- is_valid(raise_exception=False)#
- classmethod many_init(*args, **kwargs)#
This method implements the creation of a ListSerializer parent class when many=True is used. You can customize it if you need to control which keyword arguments are passed to the parent, and which are passed to the child.
Note that we’re over-cautious in passing most arguments to both parent and child classes in order to try to cover the general case. If you’re overriding this method you’ll probably want something much simpler, eg:
@classmethod def many_init(cls, *args, **kwargs):
- property root#
Returns the top-level serializer for this field.
- run_validation(data=<class 'rest_framework.fields.empty'>)#
We override the default run_validation, because the validation performed by validators and the .validate() method should be coerced into an error dictionary with a ‘non_fields_error’ key.
- run_validators(value)#
Add read_only fields with defaults to value before running validators.
- save(**kwargs)#
- serializer_choice_field#
alias of
ChoiceField
- serializer_field_mapping = {<class 'django.db.models.fields.AutoField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.BigIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.BooleanField'>: <class 'rest_framework.fields.BooleanField'>, <class 'django.db.models.fields.CharField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.CommaSeparatedIntegerField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.DateField'>: <class 'rest_framework.fields.DateField'>, <class 'django.db.models.fields.DateTimeField'>: <class 'rest_framework.fields.DateTimeField'>, <class 'django.db.models.fields.DecimalField'>: <class 'rest_framework.fields.DecimalField'>, <class 'django.db.models.fields.DurationField'>: <class 'rest_framework.fields.DurationField'>, <class 'django.db.models.fields.EmailField'>: <class 'rest_framework.fields.EmailField'>, <class 'django.db.models.fields.Field'>: <class 'rest_framework.fields.ModelField'>, <class 'django.db.models.fields.files.FileField'>: <class 'rest_framework.fields.FileField'>, <class 'django.db.models.fields.FloatField'>: <class 'rest_framework.fields.FloatField'>, <class 'django.db.models.fields.files.ImageField'>: <class 'rest_framework.fields.ImageField'>, <class 'django.db.models.fields.IntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.NullBooleanField'>: <class 'rest_framework.fields.BooleanField'>, <class 'django.db.models.fields.PositiveIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.PositiveSmallIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.SlugField'>: <class 'rest_framework.fields.SlugField'>, <class 'django.db.models.fields.SmallIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.TextField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.TimeField'>: <class 'rest_framework.fields.TimeField'>, <class 'django.db.models.fields.URLField'>: <class 'rest_framework.fields.URLField'>, <class 'django.db.models.fields.UUIDField'>: <class 'rest_framework.fields.UUIDField'>, <class 'django.db.models.fields.GenericIPAddressField'>: <class 'rest_framework.fields.IPAddressField'>, <class 'django.db.models.fields.FilePathField'>: <class 'rest_framework.fields.FilePathField'>, <class 'django.db.models.fields.json.JSONField'>: <class 'rest_framework.fields.JSONField'>, <class 'django.contrib.postgres.fields.hstore.HStoreField'>: <class 'rest_framework.fields.HStoreField'>, <class 'django.contrib.postgres.fields.array.ArrayField'>: <class 'rest_framework.fields.ListField'>, <class 'django.contrib.postgres.fields.jsonb.JSONField'>: <class 'rest_framework.fields.JSONField'>}#
alias of
PrimaryKeyRelatedField
alias of
SlugRelatedField
- serializer_url_field#
alias of
HyperlinkedIdentityField
- to_internal_value(data)#
Dict of native values <- Dict of primitive datatypes.
- to_representation(instance)#
Object instance -> Dict of primitive datatypes.
- update(instance, validated_data)#
Overloads update to use the allow_aggregation field.
- Parameters:
instance (fma_django.models.FederatedModel) – the federated model which is being updated
validated_data (dict) – metadata where allow_aggregation status is found
- Returns:
updated federated model
- Return type:
- url_field_name = None#
- validate(attrs)#
- validate_empty_values(data)#
Validate empty values, and either:
Raise ValidationError, indicating invalid data.
Raise SkipField, indicating that the field should be ignored.
Return (True, data), indicating an empty value that should be returned without any further validation being applied.
Return (False, data), indicating a non-empty value, that should have validation applied as normal.
- property validated_data#
- property validators#
- class fma_django_api.v1.serializers.ModelUpdateSerializer(*args, **kwargs)#
Bases:
ModelSerializer
The serializer for model updates.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
- property data#
- class Meta#
Bases:
object
- model#
alias of
ModelUpdate
- exclude = []#
- read_only_fields = ['status']#
- validate(data)#
Validates that the data matches the required schema.
- Parameters:
data (Any) – The model update object that the client is pushing
- Raises:
ValidationError – Data does not match the required schema
- Returns:
The validated data object
- Return type:
Any
- bind(field_name, parent)#
Initializes the field name and parent for the field instance. Called when a field is added to the parent serializer instance.
- build_field(field_name, info, model_class, nested_depth)#
Return a two tuple of (cls, kwargs) to build a serializer field with.
- build_nested_field(field_name, relation_info, nested_depth)#
Create nested fields for forward and reverse relationships.
- build_property_field(field_name, model_class)#
Create a read only field for model methods and properties.
- build_relational_field(field_name, relation_info)#
Create fields for forward and reverse relationships.
- build_standard_field(field_name, model_field)#
Create regular model fields.
- build_unknown_field(field_name, model_class)#
Raise an error on any unknown fields.
- build_url_field(field_name, model_class)#
Create a field representing the object’s own URL.
- property context#
Returns the context as passed to the root serializer on initialization.
- create(validated_data)#
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.
- default_empty_html#
alias of
empty
- default_error_messages = {'invalid': 'Invalid data. Expected a dictionary, but got {datatype}.'}#
- default_validators = []#
- property errors#
- fail(key, **kwargs)#
A helper method that simply raises a validation error.
- fields#
field_instance}.
- Type:
A dictionary of {field_name
- get_attribute(instance)#
Given the outgoing object instance, return the primitive value that should be used for this field.
- get_default()#
Return the default value to use when validating data if no input is provided for this field.
If a default has not been set for this field then this will simply raise SkipField, indicating that no value should be set in the validated data for this field.
- get_default_field_names(declared_fields, model_info)#
Return the default list of field names that will be used if the Meta.fields option is not specified.
- get_extra_kwargs()#
Return a dictionary mapping field names to a dictionary of additional keyword arguments.
- get_field_names(declared_fields, info)#
Returns the list of all field names that should be created when instantiating this serializer class. This is based on the default set of fields, but also takes into account the Meta.fields or Meta.exclude options if they have been specified.
- get_fields()#
Return the dict of field names -> field instances that should be used for self.fields when instantiating the serializer.
- get_initial()#
Return a value to use when the field is being returned as a primitive value, without any object instance.
- get_unique_for_date_validators()#
Determine a default set of validators for the following constraints:
unique_for_date
unique_for_month
unique_for_year
- get_unique_together_validators()#
Determine a default set of validators for any unique_together constraints.
- get_uniqueness_extra_kwargs(field_names, declared_fields, extra_kwargs)#
Return any additional field options that need to be included as a result of uniqueness constraints on the model. This is returned as a two-tuple of:
(‘dict of updated extra kwargs’, ‘mapping of hidden fields’)
- get_validators()#
Determine the set of validators to use when instantiating serializer.
- get_value(dictionary)#
Given the incoming primitive data, return the value for this field that should be validated and transformed to a native value.
- include_extra_kwargs(kwargs, extra_kwargs)#
Include any ‘extra_kwargs’ that have been included for this field, possibly removing any incompatible existing keyword arguments.
- initial = None#
- is_valid(raise_exception=False)#
- classmethod many_init(*args, **kwargs)#
This method implements the creation of a ListSerializer parent class when many=True is used. You can customize it if you need to control which keyword arguments are passed to the parent, and which are passed to the child.
Note that we’re over-cautious in passing most arguments to both parent and child classes in order to try to cover the general case. If you’re overriding this method you’ll probably want something much simpler, eg:
@classmethod def many_init(cls, *args, **kwargs):
- property root#
Returns the top-level serializer for this field.
- run_validation(data=<class 'rest_framework.fields.empty'>)#
We override the default run_validation, because the validation performed by validators and the .validate() method should be coerced into an error dictionary with a ‘non_fields_error’ key.
- run_validators(value)#
Add read_only fields with defaults to value before running validators.
- save(**kwargs)#
- serializer_choice_field#
alias of
ChoiceField
- serializer_field_mapping = {<class 'django.db.models.fields.AutoField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.BigIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.BooleanField'>: <class 'rest_framework.fields.BooleanField'>, <class 'django.db.models.fields.CharField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.CommaSeparatedIntegerField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.DateField'>: <class 'rest_framework.fields.DateField'>, <class 'django.db.models.fields.DateTimeField'>: <class 'rest_framework.fields.DateTimeField'>, <class 'django.db.models.fields.DecimalField'>: <class 'rest_framework.fields.DecimalField'>, <class 'django.db.models.fields.DurationField'>: <class 'rest_framework.fields.DurationField'>, <class 'django.db.models.fields.EmailField'>: <class 'rest_framework.fields.EmailField'>, <class 'django.db.models.fields.Field'>: <class 'rest_framework.fields.ModelField'>, <class 'django.db.models.fields.files.FileField'>: <class 'rest_framework.fields.FileField'>, <class 'django.db.models.fields.FloatField'>: <class 'rest_framework.fields.FloatField'>, <class 'django.db.models.fields.files.ImageField'>: <class 'rest_framework.fields.ImageField'>, <class 'django.db.models.fields.IntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.NullBooleanField'>: <class 'rest_framework.fields.BooleanField'>, <class 'django.db.models.fields.PositiveIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.PositiveSmallIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.SlugField'>: <class 'rest_framework.fields.SlugField'>, <class 'django.db.models.fields.SmallIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.TextField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.TimeField'>: <class 'rest_framework.fields.TimeField'>, <class 'django.db.models.fields.URLField'>: <class 'rest_framework.fields.URLField'>, <class 'django.db.models.fields.UUIDField'>: <class 'rest_framework.fields.UUIDField'>, <class 'django.db.models.fields.GenericIPAddressField'>: <class 'rest_framework.fields.IPAddressField'>, <class 'django.db.models.fields.FilePathField'>: <class 'rest_framework.fields.FilePathField'>, <class 'django.db.models.fields.json.JSONField'>: <class 'rest_framework.fields.JSONField'>, <class 'django.contrib.postgres.fields.hstore.HStoreField'>: <class 'rest_framework.fields.HStoreField'>, <class 'django.contrib.postgres.fields.array.ArrayField'>: <class 'rest_framework.fields.ListField'>, <class 'django.contrib.postgres.fields.jsonb.JSONField'>: <class 'rest_framework.fields.JSONField'>}#
alias of
PrimaryKeyRelatedField
alias of
SlugRelatedField
- serializer_url_field#
alias of
HyperlinkedIdentityField
- to_internal_value(data)#
Dict of native values <- Dict of primitive datatypes.
- to_representation(instance)#
Object instance -> Dict of primitive datatypes.
- update(instance, validated_data)#
- url_field_name = None#
- validate_empty_values(data)#
Validate empty values, and either:
Raise ValidationError, indicating invalid data.
Raise SkipField, indicating that the field should be ignored.
Return (True, data), indicating an empty value that should be returned without any further validation being applied.
Return (False, data), indicating a non-empty value, that should have validation applied as normal.
- property validated_data#
- property validators#
- class fma_django_api.v1.serializers.ClientModelUpdateSerializer(*args, **kwargs)#
Bases:
ModelUpdateSerializer
The serializer for model updates received from clients.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
- class Meta#
Bases:
Meta
- exclude = ['applied_aggregate', 'status']#
- read_only_fields = ['status', 'client']#
- model#
alias of
ModelUpdate
- bind(field_name, parent)#
Initializes the field name and parent for the field instance. Called when a field is added to the parent serializer instance.
- build_field(field_name, info, model_class, nested_depth)#
Return a two tuple of (cls, kwargs) to build a serializer field with.
- build_nested_field(field_name, relation_info, nested_depth)#
Create nested fields for forward and reverse relationships.
- build_property_field(field_name, model_class)#
Create a read only field for model methods and properties.
- build_relational_field(field_name, relation_info)#
Create fields for forward and reverse relationships.
- build_standard_field(field_name, model_field)#
Create regular model fields.
- build_unknown_field(field_name, model_class)#
Raise an error on any unknown fields.
- build_url_field(field_name, model_class)#
Create a field representing the object’s own URL.
- property context#
Returns the context as passed to the root serializer on initialization.
- create(validated_data)#
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.
- property data#
- default_empty_html#
alias of
empty
- default_error_messages = {'invalid': 'Invalid data. Expected a dictionary, but got {datatype}.'}#
- default_validators = []#
- property errors#
- fail(key, **kwargs)#
A helper method that simply raises a validation error.
- fields#
field_instance}.
- Type:
A dictionary of {field_name
- get_attribute(instance)#
Given the outgoing object instance, return the primitive value that should be used for this field.
- get_default()#
Return the default value to use when validating data if no input is provided for this field.
If a default has not been set for this field then this will simply raise SkipField, indicating that no value should be set in the validated data for this field.
- get_default_field_names(declared_fields, model_info)#
Return the default list of field names that will be used if the Meta.fields option is not specified.
- get_extra_kwargs()#
Return a dictionary mapping field names to a dictionary of additional keyword arguments.
- get_field_names(declared_fields, info)#
Returns the list of all field names that should be created when instantiating this serializer class. This is based on the default set of fields, but also takes into account the Meta.fields or Meta.exclude options if they have been specified.
- get_fields()#
Return the dict of field names -> field instances that should be used for self.fields when instantiating the serializer.
- get_initial()#
Return a value to use when the field is being returned as a primitive value, without any object instance.
- get_unique_for_date_validators()#
Determine a default set of validators for the following constraints:
unique_for_date
unique_for_month
unique_for_year
- get_unique_together_validators()#
Determine a default set of validators for any unique_together constraints.
- get_uniqueness_extra_kwargs(field_names, declared_fields, extra_kwargs)#
Return any additional field options that need to be included as a result of uniqueness constraints on the model. This is returned as a two-tuple of:
(‘dict of updated extra kwargs’, ‘mapping of hidden fields’)
- get_validators()#
Determine the set of validators to use when instantiating serializer.
- get_value(dictionary)#
Given the incoming primitive data, return the value for this field that should be validated and transformed to a native value.
- include_extra_kwargs(kwargs, extra_kwargs)#
Include any ‘extra_kwargs’ that have been included for this field, possibly removing any incompatible existing keyword arguments.
- initial = None#
- is_valid(raise_exception=False)#
- classmethod many_init(*args, **kwargs)#
This method implements the creation of a ListSerializer parent class when many=True is used. You can customize it if you need to control which keyword arguments are passed to the parent, and which are passed to the child.
Note that we’re over-cautious in passing most arguments to both parent and child classes in order to try to cover the general case. If you’re overriding this method you’ll probably want something much simpler, eg:
@classmethod def many_init(cls, *args, **kwargs):
- property root#
Returns the top-level serializer for this field.
- run_validation(data=<class 'rest_framework.fields.empty'>)#
We override the default run_validation, because the validation performed by validators and the .validate() method should be coerced into an error dictionary with a ‘non_fields_error’ key.
- run_validators(value)#
Add read_only fields with defaults to value before running validators.
- save(**kwargs)#
- serializer_choice_field#
alias of
ChoiceField
- serializer_field_mapping = {<class 'django.db.models.fields.AutoField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.BigIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.BooleanField'>: <class 'rest_framework.fields.BooleanField'>, <class 'django.db.models.fields.CharField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.CommaSeparatedIntegerField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.DateField'>: <class 'rest_framework.fields.DateField'>, <class 'django.db.models.fields.DateTimeField'>: <class 'rest_framework.fields.DateTimeField'>, <class 'django.db.models.fields.DecimalField'>: <class 'rest_framework.fields.DecimalField'>, <class 'django.db.models.fields.DurationField'>: <class 'rest_framework.fields.DurationField'>, <class 'django.db.models.fields.EmailField'>: <class 'rest_framework.fields.EmailField'>, <class 'django.db.models.fields.Field'>: <class 'rest_framework.fields.ModelField'>, <class 'django.db.models.fields.files.FileField'>: <class 'rest_framework.fields.FileField'>, <class 'django.db.models.fields.FloatField'>: <class 'rest_framework.fields.FloatField'>, <class 'django.db.models.fields.files.ImageField'>: <class 'rest_framework.fields.ImageField'>, <class 'django.db.models.fields.IntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.NullBooleanField'>: <class 'rest_framework.fields.BooleanField'>, <class 'django.db.models.fields.PositiveIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.PositiveSmallIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.SlugField'>: <class 'rest_framework.fields.SlugField'>, <class 'django.db.models.fields.SmallIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.TextField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.TimeField'>: <class 'rest_framework.fields.TimeField'>, <class 'django.db.models.fields.URLField'>: <class 'rest_framework.fields.URLField'>, <class 'django.db.models.fields.UUIDField'>: <class 'rest_framework.fields.UUIDField'>, <class 'django.db.models.fields.GenericIPAddressField'>: <class 'rest_framework.fields.IPAddressField'>, <class 'django.db.models.fields.FilePathField'>: <class 'rest_framework.fields.FilePathField'>, <class 'django.db.models.fields.json.JSONField'>: <class 'rest_framework.fields.JSONField'>, <class 'django.contrib.postgres.fields.hstore.HStoreField'>: <class 'rest_framework.fields.HStoreField'>, <class 'django.contrib.postgres.fields.array.ArrayField'>: <class 'rest_framework.fields.ListField'>, <class 'django.contrib.postgres.fields.jsonb.JSONField'>: <class 'rest_framework.fields.JSONField'>}#
alias of
PrimaryKeyRelatedField
alias of
SlugRelatedField
- serializer_url_field#
alias of
HyperlinkedIdentityField
- to_internal_value(data)#
Dict of native values <- Dict of primitive datatypes.
- to_representation(instance)#
Object instance -> Dict of primitive datatypes.
- update(instance, validated_data)#
- url_field_name = None#
- validate(data)#
Validates that the data matches the required schema.
- Parameters:
data (Any) – The model update object that the client is pushing
- Raises:
ValidationError – Data does not match the required schema
- Returns:
The validated data object
- Return type:
Any
- validate_empty_values(data)#
Validate empty values, and either:
Raise ValidationError, indicating invalid data.
Raise SkipField, indicating that the field should be ignored.
Return (True, data), indicating an empty value that should be returned without any further validation being applied.
Return (False, data), indicating a non-empty value, that should have validation applied as normal.
- property validated_data#
- property validators#
- class fma_django_api.v1.serializers.ModelAggregateSerializer(*args, **kwargs)#
Bases:
ModelSerializer
The serializer for model aggregates.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
- class Meta#
Bases:
object
- model#
alias of
ModelAggregate
- fields = '__all__'#
- bind(field_name, parent)#
Initializes the field name and parent for the field instance. Called when a field is added to the parent serializer instance.
- build_field(field_name, info, model_class, nested_depth)#
Return a two tuple of (cls, kwargs) to build a serializer field with.
- build_nested_field(field_name, relation_info, nested_depth)#
Create nested fields for forward and reverse relationships.
- build_property_field(field_name, model_class)#
Create a read only field for model methods and properties.
- build_relational_field(field_name, relation_info)#
Create fields for forward and reverse relationships.
- build_standard_field(field_name, model_field)#
Create regular model fields.
- build_unknown_field(field_name, model_class)#
Raise an error on any unknown fields.
- build_url_field(field_name, model_class)#
Create a field representing the object’s own URL.
- property context#
Returns the context as passed to the root serializer on initialization.
- create(validated_data)#
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.
- property data#
- default_empty_html#
alias of
empty
- default_error_messages = {'invalid': 'Invalid data. Expected a dictionary, but got {datatype}.'}#
- default_validators = []#
- property errors#
- fail(key, **kwargs)#
A helper method that simply raises a validation error.
- fields#
field_instance}.
- Type:
A dictionary of {field_name
- get_attribute(instance)#
Given the outgoing object instance, return the primitive value that should be used for this field.
- get_default()#
Return the default value to use when validating data if no input is provided for this field.
If a default has not been set for this field then this will simply raise SkipField, indicating that no value should be set in the validated data for this field.
- get_default_field_names(declared_fields, model_info)#
Return the default list of field names that will be used if the Meta.fields option is not specified.
- get_extra_kwargs()#
Return a dictionary mapping field names to a dictionary of additional keyword arguments.
- get_field_names(declared_fields, info)#
Returns the list of all field names that should be created when instantiating this serializer class. This is based on the default set of fields, but also takes into account the Meta.fields or Meta.exclude options if they have been specified.
- get_fields()#
Return the dict of field names -> field instances that should be used for self.fields when instantiating the serializer.
- get_initial()#
Return a value to use when the field is being returned as a primitive value, without any object instance.
- get_unique_for_date_validators()#
Determine a default set of validators for the following constraints:
unique_for_date
unique_for_month
unique_for_year
- get_unique_together_validators()#
Determine a default set of validators for any unique_together constraints.
- get_uniqueness_extra_kwargs(field_names, declared_fields, extra_kwargs)#
Return any additional field options that need to be included as a result of uniqueness constraints on the model. This is returned as a two-tuple of:
(‘dict of updated extra kwargs’, ‘mapping of hidden fields’)
- get_validators()#
Determine the set of validators to use when instantiating serializer.
- get_value(dictionary)#
Given the incoming primitive data, return the value for this field that should be validated and transformed to a native value.
- include_extra_kwargs(kwargs, extra_kwargs)#
Include any ‘extra_kwargs’ that have been included for this field, possibly removing any incompatible existing keyword arguments.
- initial = None#
- is_valid(raise_exception=False)#
- classmethod many_init(*args, **kwargs)#
This method implements the creation of a ListSerializer parent class when many=True is used. You can customize it if you need to control which keyword arguments are passed to the parent, and which are passed to the child.
Note that we’re over-cautious in passing most arguments to both parent and child classes in order to try to cover the general case. If you’re overriding this method you’ll probably want something much simpler, eg:
@classmethod def many_init(cls, *args, **kwargs):
- property root#
Returns the top-level serializer for this field.
- run_validation(data=<class 'rest_framework.fields.empty'>)#
We override the default run_validation, because the validation performed by validators and the .validate() method should be coerced into an error dictionary with a ‘non_fields_error’ key.
- run_validators(value)#
Add read_only fields with defaults to value before running validators.
- save(**kwargs)#
- serializer_choice_field#
alias of
ChoiceField
- serializer_field_mapping = {<class 'django.db.models.fields.AutoField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.BigIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.BooleanField'>: <class 'rest_framework.fields.BooleanField'>, <class 'django.db.models.fields.CharField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.CommaSeparatedIntegerField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.DateField'>: <class 'rest_framework.fields.DateField'>, <class 'django.db.models.fields.DateTimeField'>: <class 'rest_framework.fields.DateTimeField'>, <class 'django.db.models.fields.DecimalField'>: <class 'rest_framework.fields.DecimalField'>, <class 'django.db.models.fields.DurationField'>: <class 'rest_framework.fields.DurationField'>, <class 'django.db.models.fields.EmailField'>: <class 'rest_framework.fields.EmailField'>, <class 'django.db.models.fields.Field'>: <class 'rest_framework.fields.ModelField'>, <class 'django.db.models.fields.files.FileField'>: <class 'rest_framework.fields.FileField'>, <class 'django.db.models.fields.FloatField'>: <class 'rest_framework.fields.FloatField'>, <class 'django.db.models.fields.files.ImageField'>: <class 'rest_framework.fields.ImageField'>, <class 'django.db.models.fields.IntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.NullBooleanField'>: <class 'rest_framework.fields.BooleanField'>, <class 'django.db.models.fields.PositiveIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.PositiveSmallIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.SlugField'>: <class 'rest_framework.fields.SlugField'>, <class 'django.db.models.fields.SmallIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.TextField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.TimeField'>: <class 'rest_framework.fields.TimeField'>, <class 'django.db.models.fields.URLField'>: <class 'rest_framework.fields.URLField'>, <class 'django.db.models.fields.UUIDField'>: <class 'rest_framework.fields.UUIDField'>, <class 'django.db.models.fields.GenericIPAddressField'>: <class 'rest_framework.fields.IPAddressField'>, <class 'django.db.models.fields.FilePathField'>: <class 'rest_framework.fields.FilePathField'>, <class 'django.db.models.fields.json.JSONField'>: <class 'rest_framework.fields.JSONField'>, <class 'django.contrib.postgres.fields.hstore.HStoreField'>: <class 'rest_framework.fields.HStoreField'>, <class 'django.contrib.postgres.fields.array.ArrayField'>: <class 'rest_framework.fields.ListField'>, <class 'django.contrib.postgres.fields.jsonb.JSONField'>: <class 'rest_framework.fields.JSONField'>}#
alias of
PrimaryKeyRelatedField
alias of
SlugRelatedField
- serializer_url_field#
alias of
HyperlinkedIdentityField
- to_internal_value(data)#
Dict of native values <- Dict of primitive datatypes.
- to_representation(instance)#
Object instance -> Dict of primitive datatypes.
- update(instance, validated_data)#
- url_field_name = None#
- validate(attrs)#
- validate_empty_values(data)#
Validate empty values, and either:
Raise ValidationError, indicating invalid data.
Raise SkipField, indicating that the field should be ignored.
Return (True, data), indicating an empty value that should be returned without any further validation being applied.
Return (False, data), indicating a non-empty value, that should have validation applied as normal.
- property validated_data#
- property validators#
- class fma_django_api.v1.serializers.ModelAggregateRetrieveJSONSerializer(*args, **kwargs)#
Bases:
ModelSerializer
The serializer for model aggregates in JSON format.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
- class Meta#
Bases:
object
- model#
alias of
ModelAggregate
- fields = '__all__'#
- bind(field_name, parent)#
Initializes the field name and parent for the field instance. Called when a field is added to the parent serializer instance.
- build_field(field_name, info, model_class, nested_depth)#
Return a two tuple of (cls, kwargs) to build a serializer field with.
- build_nested_field(field_name, relation_info, nested_depth)#
Create nested fields for forward and reverse relationships.
- build_property_field(field_name, model_class)#
Create a read only field for model methods and properties.
- build_relational_field(field_name, relation_info)#
Create fields for forward and reverse relationships.
- build_standard_field(field_name, model_field)#
Create regular model fields.
- build_unknown_field(field_name, model_class)#
Raise an error on any unknown fields.
- build_url_field(field_name, model_class)#
Create a field representing the object’s own URL.
- property context#
Returns the context as passed to the root serializer on initialization.
- create(validated_data)#
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.
- property data#
- default_empty_html#
alias of
empty
- default_error_messages = {'invalid': 'Invalid data. Expected a dictionary, but got {datatype}.'}#
- default_validators = []#
- property errors#
- fail(key, **kwargs)#
A helper method that simply raises a validation error.
- fields#
field_instance}.
- Type:
A dictionary of {field_name
- get_attribute(instance)#
Given the outgoing object instance, return the primitive value that should be used for this field.
- get_default()#
Return the default value to use when validating data if no input is provided for this field.
If a default has not been set for this field then this will simply raise SkipField, indicating that no value should be set in the validated data for this field.
- get_default_field_names(declared_fields, model_info)#
Return the default list of field names that will be used if the Meta.fields option is not specified.
- get_extra_kwargs()#
Return a dictionary mapping field names to a dictionary of additional keyword arguments.
- get_field_names(declared_fields, info)#
Returns the list of all field names that should be created when instantiating this serializer class. This is based on the default set of fields, but also takes into account the Meta.fields or Meta.exclude options if they have been specified.
- get_fields()#
Return the dict of field names -> field instances that should be used for self.fields when instantiating the serializer.
- get_initial()#
Return a value to use when the field is being returned as a primitive value, without any object instance.
- get_unique_for_date_validators()#
Determine a default set of validators for the following constraints:
unique_for_date
unique_for_month
unique_for_year
- get_unique_together_validators()#
Determine a default set of validators for any unique_together constraints.
- get_uniqueness_extra_kwargs(field_names, declared_fields, extra_kwargs)#
Return any additional field options that need to be included as a result of uniqueness constraints on the model. This is returned as a two-tuple of:
(‘dict of updated extra kwargs’, ‘mapping of hidden fields’)
- get_validators()#
Determine the set of validators to use when instantiating serializer.
- get_value(dictionary)#
Given the incoming primitive data, return the value for this field that should be validated and transformed to a native value.
- include_extra_kwargs(kwargs, extra_kwargs)#
Include any ‘extra_kwargs’ that have been included for this field, possibly removing any incompatible existing keyword arguments.
- initial = None#
- is_valid(raise_exception=False)#
- classmethod many_init(*args, **kwargs)#
This method implements the creation of a ListSerializer parent class when many=True is used. You can customize it if you need to control which keyword arguments are passed to the parent, and which are passed to the child.
Note that we’re over-cautious in passing most arguments to both parent and child classes in order to try to cover the general case. If you’re overriding this method you’ll probably want something much simpler, eg:
@classmethod def many_init(cls, *args, **kwargs):
- property root#
Returns the top-level serializer for this field.
- run_validation(data=<class 'rest_framework.fields.empty'>)#
We override the default run_validation, because the validation performed by validators and the .validate() method should be coerced into an error dictionary with a ‘non_fields_error’ key.
- run_validators(value)#
Add read_only fields with defaults to value before running validators.
- save(**kwargs)#
- serializer_choice_field#
alias of
ChoiceField
- serializer_field_mapping = {<class 'django.db.models.fields.AutoField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.BigIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.BooleanField'>: <class 'rest_framework.fields.BooleanField'>, <class 'django.db.models.fields.CharField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.CommaSeparatedIntegerField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.DateField'>: <class 'rest_framework.fields.DateField'>, <class 'django.db.models.fields.DateTimeField'>: <class 'rest_framework.fields.DateTimeField'>, <class 'django.db.models.fields.DecimalField'>: <class 'rest_framework.fields.DecimalField'>, <class 'django.db.models.fields.DurationField'>: <class 'rest_framework.fields.DurationField'>, <class 'django.db.models.fields.EmailField'>: <class 'rest_framework.fields.EmailField'>, <class 'django.db.models.fields.Field'>: <class 'rest_framework.fields.ModelField'>, <class 'django.db.models.fields.files.FileField'>: <class 'rest_framework.fields.FileField'>, <class 'django.db.models.fields.FloatField'>: <class 'rest_framework.fields.FloatField'>, <class 'django.db.models.fields.files.ImageField'>: <class 'rest_framework.fields.ImageField'>, <class 'django.db.models.fields.IntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.NullBooleanField'>: <class 'rest_framework.fields.BooleanField'>, <class 'django.db.models.fields.PositiveIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.PositiveSmallIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.SlugField'>: <class 'rest_framework.fields.SlugField'>, <class 'django.db.models.fields.SmallIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.TextField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.TimeField'>: <class 'rest_framework.fields.TimeField'>, <class 'django.db.models.fields.URLField'>: <class 'rest_framework.fields.URLField'>, <class 'django.db.models.fields.UUIDField'>: <class 'rest_framework.fields.UUIDField'>, <class 'django.db.models.fields.GenericIPAddressField'>: <class 'rest_framework.fields.IPAddressField'>, <class 'django.db.models.fields.FilePathField'>: <class 'rest_framework.fields.FilePathField'>, <class 'django.db.models.fields.json.JSONField'>: <class 'rest_framework.fields.JSONField'>, <class 'django.contrib.postgres.fields.hstore.HStoreField'>: <class 'rest_framework.fields.HStoreField'>, <class 'django.contrib.postgres.fields.array.ArrayField'>: <class 'rest_framework.fields.ListField'>, <class 'django.contrib.postgres.fields.jsonb.JSONField'>: <class 'rest_framework.fields.JSONField'>}#
alias of
PrimaryKeyRelatedField
alias of
SlugRelatedField
- serializer_url_field#
alias of
HyperlinkedIdentityField
- to_internal_value(data)#
Dict of native values <- Dict of primitive datatypes.
- to_representation(instance)#
Object instance -> Dict of primitive datatypes.
- update(instance, validated_data)#
- url_field_name = None#
- validate(attrs)#
- validate_empty_values(data)#
Validate empty values, and either:
Raise ValidationError, indicating invalid data.
Raise SkipField, indicating that the field should be ignored.
Return (True, data), indicating an empty value that should be returned without any further validation being applied.
Return (False, data), indicating a non-empty value, that should have validation applied as normal.
- property validated_data#
- property validators#
- class fma_django_api.v1.serializers.PublishModelSerializer(*args, **kwargs)#
Bases:
Serializer
The serializer for published model artifacts.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
- bind(field_name, parent)#
Initializes the field name and parent for the field instance. Called when a field is added to the parent serializer instance.
- property context#
Returns the context as passed to the root serializer on initialization.
- create(validated_data)#
- property data#
- default_empty_html#
alias of
empty
- default_error_messages = {'invalid': 'Invalid data. Expected a dictionary, but got {datatype}.'}#
- default_validators = []#
- property errors#
- fail(key, **kwargs)#
A helper method that simply raises a validation error.
- fields#
field_instance}.
- Type:
A dictionary of {field_name
- get_attribute(instance)#
Given the outgoing object instance, return the primitive value that should be used for this field.
- get_default()#
Return the default value to use when validating data if no input is provided for this field.
If a default has not been set for this field then this will simply raise SkipField, indicating that no value should be set in the validated data for this field.
- get_fields()#
Returns a dictionary of {field_name: field_instance}.
- get_initial()#
Return a value to use when the field is being returned as a primitive value, without any object instance.
- get_validators()#
Returns a list of validator callables.
- get_value(dictionary)#
Given the incoming primitive data, return the value for this field that should be validated and transformed to a native value.
- initial = None#
- is_valid(raise_exception=False)#
- classmethod many_init(*args, **kwargs)#
This method implements the creation of a ListSerializer parent class when many=True is used. You can customize it if you need to control which keyword arguments are passed to the parent, and which are passed to the child.
Note that we’re over-cautious in passing most arguments to both parent and child classes in order to try to cover the general case. If you’re overriding this method you’ll probably want something much simpler, eg:
@classmethod def many_init(cls, *args, **kwargs):
- property root#
Returns the top-level serializer for this field.
- run_validation(data=<class 'rest_framework.fields.empty'>)#
We override the default run_validation, because the validation performed by validators and the .validate() method should be coerced into an error dictionary with a ‘non_fields_error’ key.
- run_validators(value)#
Add read_only fields with defaults to value before running validators.
- save(**kwargs)#
- to_internal_value(data)#
Dict of native values <- Dict of primitive datatypes.
- to_representation(instance)#
Object instance -> Dict of primitive datatypes.
- update(instance, validated_data)#
- validate(attrs)#
- validate_empty_values(data)#
Validate empty values, and either:
Raise ValidationError, indicating invalid data.
Raise SkipField, indicating that the field should be ignored.
Return (True, data), indicating an empty value that should be returned without any further validation being applied.
Return (False, data), indicating a non-empty value, that should have validation applied as normal.
- property validated_data#
- property validators#
- class fma_django_api.v1.serializers.PushValidationScore(*args, **kwargs)#
Bases:
Serializer
The serializer for pushing validation scores.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
- bind(field_name, parent)#
Initializes the field name and parent for the field instance. Called when a field is added to the parent serializer instance.
- property context#
Returns the context as passed to the root serializer on initialization.
- create(validated_data)#
- property data#
- default_empty_html#
alias of
empty
- default_error_messages = {'invalid': 'Invalid data. Expected a dictionary, but got {datatype}.'}#
- default_validators = []#
- property errors#
- fail(key, **kwargs)#
A helper method that simply raises a validation error.
- fields#
field_instance}.
- Type:
A dictionary of {field_name
- get_attribute(instance)#
Given the outgoing object instance, return the primitive value that should be used for this field.
- get_default()#
Return the default value to use when validating data if no input is provided for this field.
If a default has not been set for this field then this will simply raise SkipField, indicating that no value should be set in the validated data for this field.
- get_fields()#
Returns a dictionary of {field_name: field_instance}.
- get_initial()#
Return a value to use when the field is being returned as a primitive value, without any object instance.
- get_validators()#
Returns a list of validator callables.
- get_value(dictionary)#
Given the incoming primitive data, return the value for this field that should be validated and transformed to a native value.
- initial = None#
- is_valid(raise_exception=False)#
- classmethod many_init(*args, **kwargs)#
This method implements the creation of a ListSerializer parent class when many=True is used. You can customize it if you need to control which keyword arguments are passed to the parent, and which are passed to the child.
Note that we’re over-cautious in passing most arguments to both parent and child classes in order to try to cover the general case. If you’re overriding this method you’ll probably want something much simpler, eg:
@classmethod def many_init(cls, *args, **kwargs):
- property root#
Returns the top-level serializer for this field.
- run_validation(data=<class 'rest_framework.fields.empty'>)#
We override the default run_validation, because the validation performed by validators and the .validate() method should be coerced into an error dictionary with a ‘non_fields_error’ key.
- run_validators(value)#
Add read_only fields with defaults to value before running validators.
- save(**kwargs)#
- to_internal_value(data)#
Dict of native values <- Dict of primitive datatypes.
- to_representation(instance)#
Object instance -> Dict of primitive datatypes.
- update(instance, validated_data)#
- validate(attrs)#
- validate_empty_values(data)#
Validate empty values, and either:
Raise ValidationError, indicating invalid data.
Raise SkipField, indicating that the field should be ignored.
Return (True, data), indicating an empty value that should be returned without any further validation being applied.
Return (False, data), indicating a non-empty value, that should have validation applied as normal.
- property validated_data#
- property validators#
- class fma_django_api.v1.serializers.ClientAggregateScoreSerializer(*args, **kwargs)#
Bases:
ModelSerializer
The serializer for client aggregate validation scores.
When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
- class Meta#
Bases:
object
- model#
alias of
ClientAggregateScore
- fields = '__all__'#
- validate(results)#
Validates that the results matches the required schema.
- Parameters:
results (Any) – The scores output from some evaluation metric
- Raises:
ValidationError – Data does not match the required schema
- Returns:
The validated results object
- Return type:
Any
- bind(field_name, parent)#
Initializes the field name and parent for the field instance. Called when a field is added to the parent serializer instance.
- build_field(field_name, info, model_class, nested_depth)#
Return a two tuple of (cls, kwargs) to build a serializer field with.
- build_nested_field(field_name, relation_info, nested_depth)#
Create nested fields for forward and reverse relationships.
- build_property_field(field_name, model_class)#
Create a read only field for model methods and properties.
- build_relational_field(field_name, relation_info)#
Create fields for forward and reverse relationships.
- build_standard_field(field_name, model_field)#
Create regular model fields.
- build_unknown_field(field_name, model_class)#
Raise an error on any unknown fields.
- build_url_field(field_name, model_class)#
Create a field representing the object’s own URL.
- property context#
Returns the context as passed to the root serializer on initialization.
- create(validated_data)#
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.
- property data#
- default_empty_html#
alias of
empty
- default_error_messages = {'invalid': 'Invalid data. Expected a dictionary, but got {datatype}.'}#
- default_validators = []#
- property errors#
- fail(key, **kwargs)#
A helper method that simply raises a validation error.
- fields#
field_instance}.
- Type:
A dictionary of {field_name
- get_attribute(instance)#
Given the outgoing object instance, return the primitive value that should be used for this field.
- get_default()#
Return the default value to use when validating data if no input is provided for this field.
If a default has not been set for this field then this will simply raise SkipField, indicating that no value should be set in the validated data for this field.
- get_default_field_names(declared_fields, model_info)#
Return the default list of field names that will be used if the Meta.fields option is not specified.
- get_extra_kwargs()#
Return a dictionary mapping field names to a dictionary of additional keyword arguments.
- get_field_names(declared_fields, info)#
Returns the list of all field names that should be created when instantiating this serializer class. This is based on the default set of fields, but also takes into account the Meta.fields or Meta.exclude options if they have been specified.
- get_fields()#
Return the dict of field names -> field instances that should be used for self.fields when instantiating the serializer.
- get_initial()#
Return a value to use when the field is being returned as a primitive value, without any object instance.
- get_unique_for_date_validators()#
Determine a default set of validators for the following constraints:
unique_for_date
unique_for_month
unique_for_year
- get_unique_together_validators()#
Determine a default set of validators for any unique_together constraints.
- get_uniqueness_extra_kwargs(field_names, declared_fields, extra_kwargs)#
Return any additional field options that need to be included as a result of uniqueness constraints on the model. This is returned as a two-tuple of:
(‘dict of updated extra kwargs’, ‘mapping of hidden fields’)
- get_validators()#
Determine the set of validators to use when instantiating serializer.
- get_value(dictionary)#
Given the incoming primitive data, return the value for this field that should be validated and transformed to a native value.
- include_extra_kwargs(kwargs, extra_kwargs)#
Include any ‘extra_kwargs’ that have been included for this field, possibly removing any incompatible existing keyword arguments.
- initial = None#
- is_valid(raise_exception=False)#
- classmethod many_init(*args, **kwargs)#
This method implements the creation of a ListSerializer parent class when many=True is used. You can customize it if you need to control which keyword arguments are passed to the parent, and which are passed to the child.
Note that we’re over-cautious in passing most arguments to both parent and child classes in order to try to cover the general case. If you’re overriding this method you’ll probably want something much simpler, eg:
@classmethod def many_init(cls, *args, **kwargs):
- property root#
Returns the top-level serializer for this field.
- run_validation(data=<class 'rest_framework.fields.empty'>)#
We override the default run_validation, because the validation performed by validators and the .validate() method should be coerced into an error dictionary with a ‘non_fields_error’ key.
- run_validators(value)#
Add read_only fields with defaults to value before running validators.
- save(**kwargs)#
- serializer_choice_field#
alias of
ChoiceField
- serializer_field_mapping = {<class 'django.db.models.fields.AutoField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.BigIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.BooleanField'>: <class 'rest_framework.fields.BooleanField'>, <class 'django.db.models.fields.CharField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.CommaSeparatedIntegerField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.DateField'>: <class 'rest_framework.fields.DateField'>, <class 'django.db.models.fields.DateTimeField'>: <class 'rest_framework.fields.DateTimeField'>, <class 'django.db.models.fields.DecimalField'>: <class 'rest_framework.fields.DecimalField'>, <class 'django.db.models.fields.DurationField'>: <class 'rest_framework.fields.DurationField'>, <class 'django.db.models.fields.EmailField'>: <class 'rest_framework.fields.EmailField'>, <class 'django.db.models.fields.Field'>: <class 'rest_framework.fields.ModelField'>, <class 'django.db.models.fields.files.FileField'>: <class 'rest_framework.fields.FileField'>, <class 'django.db.models.fields.FloatField'>: <class 'rest_framework.fields.FloatField'>, <class 'django.db.models.fields.files.ImageField'>: <class 'rest_framework.fields.ImageField'>, <class 'django.db.models.fields.IntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.NullBooleanField'>: <class 'rest_framework.fields.BooleanField'>, <class 'django.db.models.fields.PositiveIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.PositiveSmallIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.SlugField'>: <class 'rest_framework.fields.SlugField'>, <class 'django.db.models.fields.SmallIntegerField'>: <class 'rest_framework.fields.IntegerField'>, <class 'django.db.models.fields.TextField'>: <class 'rest_framework.fields.CharField'>, <class 'django.db.models.fields.TimeField'>: <class 'rest_framework.fields.TimeField'>, <class 'django.db.models.fields.URLField'>: <class 'rest_framework.fields.URLField'>, <class 'django.db.models.fields.UUIDField'>: <class 'rest_framework.fields.UUIDField'>, <class 'django.db.models.fields.GenericIPAddressField'>: <class 'rest_framework.fields.IPAddressField'>, <class 'django.db.models.fields.FilePathField'>: <class 'rest_framework.fields.FilePathField'>, <class 'django.db.models.fields.json.JSONField'>: <class 'rest_framework.fields.JSONField'>, <class 'django.contrib.postgres.fields.hstore.HStoreField'>: <class 'rest_framework.fields.HStoreField'>, <class 'django.contrib.postgres.fields.array.ArrayField'>: <class 'rest_framework.fields.ListField'>, <class 'django.contrib.postgres.fields.jsonb.JSONField'>: <class 'rest_framework.fields.JSONField'>}#
alias of
PrimaryKeyRelatedField
alias of
SlugRelatedField
- serializer_url_field#
alias of
HyperlinkedIdentityField
- to_internal_value(data)#
Dict of native values <- Dict of primitive datatypes.
- to_representation(instance)#
Object instance -> Dict of primitive datatypes.
- update(instance, validated_data)#
- url_field_name = None#
- validate_empty_values(data)#
Validate empty values, and either:
Raise ValidationError, indicating invalid data.
Raise SkipField, indicating that the field should be ignored.
Return (True, data), indicating an empty value that should be returned without any further validation being applied.
Return (False, data), indicating a non-empty value, that should have validation applied as normal.
- property validated_data#
- property validators#