[Answered ]-Django REST Framework: Purpose of CreateOnlyDefault

2👍

When CreateOnlyDefault is used, the value will only be used on creation not on updates.

For example:

class MySerializer:
    created = serializers.DateTimeField(
        read_only=True,
        default=serializers.CreateOnlyDefault(timezone.now)
    )
    modified = serializers.DateTimeField(
        read_only=True,
        default=timezone.now
    )

With that serializer, modified field will be updated every on every update whereas created field will stay the same from creation.

0👍

It’s mean it can be provided by the API client or not, so when it’s checked by the validator if nothing is provided its create a ‘Default’ value.

Leave a comment