Comments (5)
Thanks for this. I was using a different implementation with v4.0 which broke when I upgraded to v4.1.2. This fixed it for me.
from django-timezone-field.
class TimeZoneSerializerField(serializers.ChoiceField):
def __init__(self, **kwargs):
super().__init__(TimeZoneField.default_choices, **kwargs)
def to_representation(self, value):
return str(super().to_representation(value))
This is how I do it now. Maybe this could be incorporated into this package. It now shows a list of all possible timezone fields in the browsable API and in the in an OPTIONS request.
from django-timezone-field.
Agreed it would be great to respond to an OPTIONS
request with the list of possible choices. I didn't realize that was provided by django rest framework choice field.
@gabn88 would it be possible to expand the field class you have there to accept an optional choices
argument? The idea would be to support the case where someone wants the serializer field to only display a subset of all possible timezone choices.
I think if that was added to this implementation, and then also some basic tests, we could merge it in named something like TimeZoneSerializerChoiceField
. Then it could live in parallel with the currently-existing TimeZoneSerializerField
which we would need to keep around for backwards-compatibility till at least the next major version bump.
from django-timezone-field.
class TimeZoneSerializerField(serializers.ChoiceField): def __init__(self, **kwargs): super().__init__(TimeZoneField.default_choices, **kwargs) def to_representation(self, value): return str(super().to_representation(value))
This is how I do it now. Maybe this could be incorporated into this package. It now shows a list of all possible timezone fields in the browsable API and in the in an OPTIONS request.
@gabn88 How are you dealing with this now? As far as I've seen, there is no .default_choices anymore. Or do you stick with an old version?
from django-timezone-field.
@normic I use it like this
class TimeZoneSerializerChoiceField(TimeZoneSerializerField, serializers.ChoiceField):
def __init__(self, **kwargs):
self.use_pytz = kwargs.pop("use_pytz", None)
self.tz_backend = get_tz_backend(use_pytz=self.use_pytz)
super().__init__([(tz, tz) for tz in self.tz_backend.base_tzstrs], **kwargs)
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.
- stdlib zoneinfo support HOT 7
- 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.