#NEWLINE# def copy_threshold_from_previous_price_estimate( sender , instance , created = False , **kwargs ) : #NEWLINE# #INDENT# if created : #NEWLINE# #INDENT# current_date = datetime . date . today ( ) . replace ( year = instance . year , month = instance . month , day = 1 ) #NEWLINE# prev_date = ( current_date - relativedelta ( months = 1 ) ) #NEWLINE# try : #NEWLINE# #INDENT# prev_estimate = models . PriceEstimate . objects . get ( year = prev_date . year , month = prev_date . month , scope = instance . scope , threshold__gt = 0 ) #NEWLINE# instance . threshold = prev_estimate . threshold #NEWLINE# instance . save ( update_fields = [ 'threshold' ] ) #NEWLINE# #UNINDENT# except models . PriceEstimate . DoesNotExist : #NEWLINE# #INDENT# pass