What Does That Mean? • Useful pieces of Django code. • Considered public API. • Documentation is available (sort of). • Mainly used within Django itself.
Or you can use cached_property from django.utils.functional import cached_property @cached_property def name(self): return self._request_colour_name(self.hex)
All you Need To Know from django.utils.functional import cached_property • Only cached for the lifetime of the instance. • Be careful with querysets. • Django docs • Source
It looks like this from django.utils.module_loading import import_string get_func = import_string('requests.get') print get_func # get_func('https://google.ca') #
Where is it useful? • Accessing settings at parse time, e.g. class attributes. • Translating strings outside of a view. • Translations in the settings module.
How can we fix it? from django.utils.functional import lazy class UserSignupView(CreateView): ... success_url = lazy(reverse('signup-confirmed'), unicode)
Lazy Django • The Settings object is lazy. • Several helpers have lazy siblings: • reverse_lazy • ugettext_lazy • Not sure what lazy_property is useful for.
All you Need To Know from django.utils.functional import lazy from django.utils.functional import SimpleLazyObject • Imports a class or function from a dotted path. • Django docs • Source
All you Need To Know from django.test import RequestFactory • Creates a fake request for given URL. • Can handle all HTTP methods. • Will save you some mocking work. • Django docs • Source