Skip to content

Saving an instance stores the timezone and applies it to all read operations #20

Open
@deceze

Description

@deceze

LinkedTZDateTimeField.pre_save calls _convert_value which calls _get_populate_from which does self.timezone = tz. Now the timezone used to save the instance is stored "statically" in the field.

Reading records from the database uses:

def to_python(self, value):
    """Convert the value to the appropriate timezone."""
    # pylint: disable=newstyle
    value = super(LinkedTZDateTimeField, self).to_python(value)

    if not value:
        return value

    return value.astimezone(self.timezone)  # 👈

So the timezone of the last saved instance is applied to all read instances, even if they may have other timezones.

Activity

pjrulez

pjrulez commented on Nov 3, 2024

@pjrulez

Is there an alternative maintained package?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @deceze@pjrulez

        Issue actions

          Saving an instance stores the timezone and applies it to all read operations · Issue #20 · michaeljohnbarr/django-timezone-utils