HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/aigenerator/venv/lib/python3.12/site-packages/timezone_field/utils.py
from django.db.models.query_utils import DeferredAttribute


class AutoDeserializedAttribute(DeferredAttribute):
    """
    Use as the descriptor_class for a Django custom field.
    Allows setting the field to a serialized (typically string) value,
    and immediately reflecting that as the deserialized `to_python` value.

    (This requires that the field's `to_python` returns the same thing
    whether called with a serialized or deserialized value.)
    """

    # (Adapted from django.db.models.fields.subclassing.Creator,
    # which was included in Django 1.8 and earlier.)

    def __set__(self, instance, value):
        value = self.field.to_python(value)
        instance.__dict__[self.field.attname] = value