Django timezone fields are built upon pytz timezones, but some of the timezones of the latter are not valid for the fields. With a model like
from django.db import models
from timezone_field import TimeZoneField
class TestModel(models.Model):
timezone_field = TimeZoneField(default='UTC')
def save(self, *args, **kwargs):
self.clean()
self.full_clean()
super().save(*args, **kwargs)
If I run (in a shell)
import pytz
from models import TestModel
model = TestModel.objects.get(id=1)
for zone in pytz.all_timezones:
model.timezone = zone
model.save()
I get
django.core.exceptions.ValidationError: {'timezone': ["Value <DstTzInfo 'Africa/Asmera' LMT+2:27:00 STD> is not a valid choice."]}
So it fails first on 'Africa/Asmera'
(it fails on others too, e.g. 'GMT+0'
).
Any idea of how to resolve this inconsistency? At the moment the user can select a timezone on the frontend that will give a backend error (the frontend is built in React and gets the timezones from moment timezone)