Comments (6)
To enforce that the model must have a time zone - what if you set blank=False
on the field ?
from django-timezone-field.
I have set blank=False
. That only applies to forms, so any API interactions can still create an object without a time zone.
from django-timezone-field.
Could you call model.full_clean()
or model.clean_fields()
?
As you probably saw, this is based on the CharField... as such given the choice of how to save empty values to the DB - the choice is either to use the empty string or to actually save a null value. I'd rather go with the default behavior for the CharField, which is to use the empty string.
from django-timezone-field.
That might make sense if TimeZoneField
was basically a CharField
with custom choices and validation, but no -- to_python()
does not return a string, it returns a timezone object. If there is no timezone, the python representation of the field should be None
.
The default behavior of CharField
is not to represent None
as the empty string. The default behavior, if you set null=False
and try to set the value to None
, is an IntegrityError
.
from django-timezone-field.
I'd use the model clean()
methods to do validation rather than rely on my DB to throw integrity errors... that's what they're there for.
In any case, you're welcome to fork the project and change the implementation around so that those integrity errors are thrown in the right spots for you.
from django-timezone-field.
I don't get why this library has to go against the normal convention in Django form fields.
My organization is also not able to use your latest code for the exact same reason that @hwkns brought up.
from django-timezone-field.
Related Issues (20)
- NonExistentTimeError thrown during DST transition HOT 4
- Raise exception on init HOT 3
- pytz.exceptions.AmbiguousTimeError during DST changes if created with choices_display='WITH_GMT_OFFSET' HOT 3
- How to set Default Timezone in the form HOT 1
- choices_display='WITH_GMT_OFFSET' kwarg causes django migrations to generate many AlterField() statements HOT 7
- DRF TimezoneField not rendering correctly to the openapi spec with SchemaView HOT 3
- 'TimeZoneField' has no attribute 'default_choices' HOT 4
- is INSTALLED_APPS needed? HOT 1
- Cannot install from sdist HOT 1
- 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.