Git Product home page Git Product logo

Comments (6)

mfogel avatar mfogel commented on June 2, 2024

To enforce that the model must have a time zone - what if you set blank=False on the field ?

from django-timezone-field.

hwkns avatar hwkns commented on June 2, 2024

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.

mfogel avatar mfogel commented on June 2, 2024

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.

hwkns avatar hwkns commented on June 2, 2024

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.

mfogel avatar mfogel commented on June 2, 2024

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.

diwu1989 avatar diwu1989 commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.