Time formatting in Django rest framework #237
Closed
akbari-hossein
started this conversation in
General
Replies: 2 comments
-
I think you can change the field serialization by defining your custom method like: class PostSerializer(serializers.ModelSerializer):
class Meta:
model = Post
fields = '__all__'
def get_created_at(self, obj):
<return date in your custom format> It is describe in DRF doc |
Beta Was this translation helpful? Give feedback.
0 replies
-
thanks for your replay
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
hi, I use the Django rest framework and there is a problem with time formatting
how can I change the format of time like this
15 مهر ۱۴۰۲ ساعت ۱۵:۲۰
instead of this
1402-12-29T14:41:02.919282+0330
the document said to use
{{ my_date|jformat:"%A %d %B %Y %H:%M" }} {# specific formatting #}
but it is for templates only, I am using the Django rest framework!
here is my model and resializer:
is there any extra setting?
Beta Was this translation helpful? Give feedback.
All reactions