Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 1.7 Admin - How to hide timezone warning?

I upgraded to Django 1.7 recently, and I'm starting to see these timezone warnings on DateTime/Time fields when my local timezone differs from the server timezone when I view them in the admin interface. I definitely understand why they added this, and it remove a lot of ambiguity, especially with DateTime, but I have a TimeField that actually stores time respective to the logged-in user's timezone (as saved on their user profile), so the warning message is actually misleading in that case. I've also seen that it is indeed Django 1.7 that has added this functionality (see https://github.com/django/django/blob/master/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js#L63 and https://docs.djangoproject.com/en/dev/releases/1.7/#admin-shortcuts-support-time-zones).

My question is how do I turn off these messages from showing? If so, is there a way I can specify how to hide the warnings on a per-field basis?

like image 236
fangsterr Avatar asked Dec 14 '22 19:12

fangsterr


1 Answers

If you add a Media class to your ModelAdmin you can include a CSS file that makes those warnings disappear.

# admin.py
class MyModelAdmin(ModelAdmin):
    model = MyModel
    
    class Media(object):
        css = {'all': ('no-more-warnings.css', )}

The created CSS file should include the following rule:

/* no-more-warnings.css */
.timezonewarning {
  display: none;
}
like image 106
xj9 Avatar answered Jan 28 '23 18:01

xj9