Comments (5)
By analogy with other complex fields, such as ForeignKey
s, another approach is to have a hidden field <fieldname>_code
that is just a CharField
with simple choices
, and then wrap that in a writable property <fieldname>
where you can write and read pytz objects.
(For a ForeignKey
the analogue is <fieldname>_id
which is just an int
and <fieldname>
where you read and write model objects)
from django-timezone-field.
Thanks. If I change the choices field to
CHOICES = [(tz, tz) for tz in pytz.all_timezones]
I get a whole bunch of test failures. So I'm a bit hesitant to make the change - I don't want to cause backward compatibility problems for people using the app. If you can construct a pull request that makes this change, and avoids likely backward compatibility issues... I'll entertain it.
from django-timezone-field.
This also causes problems with the new Django 1.7 migrations. Because timezone objects cannot be serialized, this makes migrations impossible.
Using the above new CHOICES
code that uses a string value for both values in the tuple works.
An alternative solution that worked for me was to remove the choices
attribute in the deconstruct
method, but this is unideal and not a great workaround.
from django-timezone-field.
I'm hoping to get a chance to address this this weekend. Thanks guys.
from django-timezone-field.
I took the time to look deeper into this. The long and the short of this is - the docs were misleading. In general, the python representation of a field's value will not match the value stored in the database. The choices attribute of a field is expected to be of the form (python representation, human readable string)
. The database-level representation never comes into play here - how could it? It might be different on different DB platforms. The model field in intended to provide an abstraction such that other parts of the code don't have to (can't?) know about the database-level representation of the value.
I filed a ticket with django on clarifying the docs and adding a test to verify this is and stays the correct behavior. The patch has been accepted and merged in.
This doesn't address the django 1.7 incompatibility referenced here, which is certainly valid. But as there's several other tickets open about this now, I'm going to close this one and we can work through the django 1.7 issues on those other tickets.
from django-timezone-field.
Related Issues (20)
- Support Django 4.2 HOT 2
- Django <= 3.X defaults to using ZoneInfoBackend instead of PYTZBackend HOT 2
- use_pytz=True doesn't seem to be default on django 3.2.21 HOT 1
- Django 5.0 support HOT 4
- Using the "Factory" timezone on systems that use the system zoneinfo database can cause problems HOT 1
- sorting list of timezones on ModelForm? HOT 1
- Great
- Does not support Django5 - This blocks upgrades HOT 6
- Requested setting USE_DEPRECATED_PYTZ, but settings are not configured.
- How to convert timezone name to Coordinated Universal Time (UTC)
- 5.0 - No time zone found with key Pacific/Kanto HOT 4
- Translate list items based on current locale HOT 1
- System timezones or installed tzdata may not cover pytz.common_timezones HOT 5
- `TimeZoneSerializerField` does not handle the empty string case
- python3.10 support HOT 1
- Version 5.0 drops Django 3.1 support, but can be installed alongside it
- Help to fix 'Pacific/Fiji' timezone ValueError: Extraneous characters at end of TZ string HOT 1
- PYTZ 2022.2 Update Issues HOT 7
- KeyError: "choices" during migration after upgrading to 5.0 HOT 4
- Use `zoneinfo.available_timezones` instead of `pytz.common_timezones` converted to `ZoneInfo` HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-timezone-field.