I stumbled across a django.utils.functional.__proxy__
object many times, last time in the following bit of code:
def formfield_for_choice_field(self, db_field, request, **kwargs):
print db_field.help_text
(With the result of the print being <django.utils.functional.__proxy__ object at 0x7fc6940106d0>
)
Now, why are things wrapped around this object? What is the main purpose of it? And more important, how can I access the value behind the proxy object? I viewed Django's source, I've seen something about lazy evaluation, but there are too many wrappers and wrapped objects to fully comprehend what's going on. Any details on this would be highly appreciated.
Django Utils is a collection of small Django helper functions and classes which make common patterns shorter and easier.
SimpleLazyObject , itself is a subclass of LazyObject . LazyObject is, as described by the actual code: A wrapper for another class that can be used to delay instantiation of the wrapped class.
It is a translation string – a string that has been marked as translated but whose actual translation result isn’t determined until the object is used in a string. See Django documentation: https://docs.djangoproject.com/en/dev/ref/unicode/#translated-strings.
Calling unicode(object)
will generate a Unicode string. Also, if you call __dict__
of the object, you can find its data under _proxy____args
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With