Ticket #1414: lazydate-attributes.diff

File lazydate-attributes.diff, 789 bytes (added by akaihola, 9 years ago)

serve missing LazyDate attributes from datetime computed at runtime

  • magic-removal/django/db/models/__init__.py

     
    2727    def __init__(self, **kwargs):
    2828        self.delta = datetime.timedelta(**kwargs)
    2929
    30     def __str__(self):
    31         return str(self.__get_value__())
    32 
    3330    def __repr__(self):
    3431        return "<LazyDate: %s>" % self.delta
    3532
    3633    def __get_value__(self):
    3734        return datetime.datetime.now() + self.delta
     35
     36    def __getattr__(self, attr):
     37        """
     38        Catch missing attributes and serve them from the datetime
     39        calculated at run time.
     40        """
     41        return getattr(self.__get_value__(), attr)
Back to Top