[Fixed]-How can I calculate a date in a Django model?

1๐Ÿ‘

โœ…

As a @propery method is accessed like a normal property call it contingency_end_date. No get as a prefix. consider using a cached_propery.

You do not have to wrap your date field into a datetime.date. It already is a date object when fetched from the database.

@cached_property
def contingency_end_date(self):
    return self.contingency_start_date +       
                 timedelta(days=self.contingency_period_in_days)

Accessing it in the template should work with {{ lease.contingency_end_date }}

Did you verify that your lease instance actually has a contingency_start_date set?

๐Ÿ‘คtrixn

Leave a comment