how to change date time format in admin panel? #212
Replies: 2 comments 2 replies
-
Hi, What is your Django and Django-Jalali version? Where do you check the fields in the admin panel? on the object view page? |
Beta Was this translation helpful? Give feedback.
-
Django DateTimeField follow the format defined in DATETIME_FORMAT. So, by changing this setting, the format of datetime displayed in the admin listview and changeview will change. But unfortunately, Django-jalali doesn't follow this setting. So, you can add a method and decorate it with @admin.register(ProductBasedOnTime)
class ProductBasedOnTimeAdmin(admin.ModelAdmin):
fields = ( "formatted_created_at", "updated_at")
readonly_fields = ("formatted_created_at", "updated_at")
@admin.display(description='Created At')
def formatted_created_at(self, obj):
return obj.created_at.strftime("%H:%M:%S _ %y/%m/%d") BTW, we need to change
|
Beta Was this translation helpful? Give feedback.
-
Hi, I added two field in my model:
created_at = jmodels.jDateTimeField(auto_now_add=True, null=True, blank=True)
updated_at = jmodels.jDateTimeField(auto_now=True, null=True, blank=True)
But the display of these fields in django admin panel is not in the format I want:
1401-12-01 19:31:18.118063+0330
Beta Was this translation helpful? Give feedback.
All reactions