I have a model with a timezone aware field.
I can easily display this datetime info in the admin change list view using the timezone I want, as it is shown in the code snapshots below.
What I cannot understand is why in the change view, this fatetime field is shown with a timezone which is neither the settings.TIME_ZONE, neither the timezone I used in the change list view.
Some idea or experience about this?
The code:
settings.py:
TIME_ZONE = 'Europe/Madrid'
LOS_ANGELES_TIME_ZONE= pytz.timezone('America/Los_Angeles')
models.py:
class BaseOrder(models.Model):
payment_time_stamp = models.DateTimeField(verbose_name='Payment time stamp', blank=True, null=True)
Admin.py (where I cannot use "payment_time_stamp2" in "fieldsets", as it is not a field of the Order model:
class OrderAdmin(ModelAdmin):
list_display = ('id', 'user', 'status', 'order_total', 'payment_time_stamp2')
fieldsets = (
(None, {'fields': ('invoice_number', 'user', 'status', 'payment_time_stamp')}),
(_('Billing'), {
'fields': ('billing_address_text',)
}),
)
def payment_time_stamp2(self, obj):
return obj.created.astimezone(settings.LOS_ANGELES_TIME_ZONE)
payment_time_stamp2.short_description = "Payment time stamp"