Python/Django Calculate Expiration for Model
Question: I have been unsuccessfully trying to calculate an expiration hour/minute for a
Django model that I have. Here is the base code I am working with:

    
    
    class Bribe(models.Model)
        date_offered = models.DateTimeField()
    
        def expiration(self):
            [...]
            return [Hours:Minutes until expiration]
    

My main goal is to calculate a countdown for how long a Bribe has until it
will expire, in this case 48 hours. For example, if a Bribe has a
`date_offered` value of `February 10th, 2015 @ 12:00PM`, I would like `def
expiration(self)` to return a string of `12 hours 10 minutes remaining until
expiration` if the current date is `February 11th 2015 @ 11:50PM`

If anyone can help me fill in what goes inside the function/method, I would
greatly appreciate it.


Answer: You can use the `timeuntil()` function which is used for the
[`timeuntil`](https://docs.djangoproject.com/en/1.7/ref/templates/builtins/#timeuntil)
template filter:

    
    
    from django.utils.timesince import timeuntil
    
    def expiration(self):
        return timeuntil(self.date_offered)
    

