I have drf model which is containe DateField. That field default format is "YYYY-MM-DD" just i want to convert "DD-MM-YYYY" how can is possible.
from rest_framework import serializers
from.models import SpaUser
from djoser.serializers import UserCreateSerializer as BaseUserRegistrationSerializer
import datetime
from rest_framework.settings import api_settings
class SpaUserSerializer(serializers.ModelSerializer):
date_joined = serializers.ReadOnlyField()
birthdate = serializers.DateField(format="%d-%m-%Y", input_formats=['%d-%m-%Y',])
If it is universal, in your settings file add "DATE_INPUT_FORMATS"
to REST_FRAMEWORK
settings like:
REST_FRAMEWORK = {
"DATE_INPUT_FORMATS": ["%d-%m-%Y"],
...
}
for more details check http://www.django-rest-framework.org/api-guide/settings/#date-and-time-formatting
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With