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.
- [Answered ]-Static fiels doesn't load in django 1.11
- [Answered ]-How to write get and post test methods for views in django?
- [Answered ]-Django Rest Framework User and UserRole and Permission Handling using Token Authentication
- [Answered ]-Django access m2m field attribute from a queryset
Source:stackexchange.com