1

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"
Simo
  • 11
  • 5
  • possible duplicate of [django admin: How to customize one field in fieldsets?](http://stackoverflow.com/questions/15228301/django-admin-how-to-customize-one-field-in-fieldsets) – Leistungsabfall Oct 09 '14 at 15:19
  • @Leistungsabfall : I don´t think so, because the "formfield_for_foreignkey" method suggested in the question you pointed out allows you to override the default formfield for a foreign keys field. But here there is no Foreign Key Field. – Simo Oct 09 '14 at 15:39
  • Oh, my bad! I'm sorry. – Leistungsabfall Oct 09 '14 at 15:41

0 Answers0