Djamo Serializers

You can use serializers to use validation and serialization on an specific field data.

class djamo.serializers.Serializer(required=False, default=None)

Base class for all the serializer classes. A serializer is a class that is responsible for serializing/de-serializing a value for an specific field of a document that specified by user in document class.

Parameters:
  • required – If True the field is required and should have a value in transaction time. default False
  • default – Default value of the field.
exception NotImplemented

This exception will raise if any necessary methods does not override in subclasses.

exception Serializer.ValidationError

This exception will raise in case of any validation problem.

Serializer.default_value

The default value specified by user.

Serializer.deserialize(self, value)

De-serialize the given value

Serializer.is_required

Return True if _required set to true.

Serializer.is_valid_value(self, value)

Check the value against current serializer policy. The difference between this method and validate method is that this method just check value to possiblity of a valid value. But validate check other parameter too like field requirement.

Serializer.serialize(self, value, **kwargs)

Serialize the given value.

Serializer.validate(self, key, value)

Validate the value parameter against current serializer policy and riase :py:exception: ~djamo.serializers.Serializer.ValidationError if value was not valid.

String Serializers

class djamo.serializers.String(min_length=None, max_length=None, *args, **kwargs)

Serializer for string data.

Parameters:
  • min_length – This parameter specify the minimum length of the string.
  • max_length – This parameter specify the maximum length of the string.
deserialize(self, value)

De-serialize the given value

is_valid_value(self, value)

Check the value against current serializer policy. The difference between this method and validate method is that this method just check value to possiblity of a valid value. But validate check other parameter too like field requirement.

serialize(self, value, **kwargs)

Serialize the given value.

u(self, value)

cast the given value to unicode

validate(self, key, value)

Check for a valid string in given value

Numeric Serializers

class djamo.serializers.Integer(min_value=None, max_value=None, klass=<class 'int'>, *args, **kwargs)

Serializer for Integer data.

Parameters:
  • min_value – This parameter specify the minimum value of the integer.
  • max_value – This parameter specify the maximum value of the integer.
deserialize(self, value)

De-serialize the given value

is_valid_value(self, value)

Check the value against current serializer policy. The difference between this method and validate method is that this method just check value to possiblity of a valid value. But validate check other parameter too like field requirement.

serialize(self, value, **kwargs)

Serialize the given value.

validate(self, key, value)

Check for a valid integer in given value

class djamo.serializers.Float(min_value=None, max_value=None, required=False, default=None, *args, **kwargs)

Serializer for Long data.

Parameters:
  • min_value – This parameter specify the minimum value of the long data.
  • max_value – This parameter specify the maximum value of the long data.

Iterable Serializers

class djamo.serializers.List(data_type=None, *args, **kwargs)

Serializer for a list of data.

deserialize(self, value)

De-serialize the given value

is_valid_value(self, value)

Check the value against current serializer policy. The difference between this method and validate method is that this method just check value to possiblity of a valid value. But validate check other parameter too like field requirement.

serialize(self, value, **kwargs)

Serialize the given value.

validate(self, key, value)

Validate the value parameter against current serializer policy and riase :py:exception: ~djamo.serializers.Serializer.ValidationError if value was not valid.

Django User Serializer

class djamo.serializers.DjangoUser(user_field='pk', *args, **kwargs)

Serializer for Django users, This class will de-serialize the data from the database to a django user and serialize the user normally to its user id.

deserialize(self, value)

Restore the string to Djano User.

serialize(self, value, **kwargs)

Convert the Django User instance to an string.

validate(self, key, value)

Check for a valid Django user in given value

Table Of Contents

This Page