code: def _calculate_day_cost(self, plan, period):
          
  
          plan_pricings = plan.planpricing_set.order_by('-pricing__period').select_related('pricing')
          selected_pricing = None
          for plan_pricing in plan_pricings:
              selected_pricing = plan_pricing
              if plan_pricing.pricing.period <= period:
                  break
  
          if selected_pricing:
              return (selected_pricing.price / selected_pricing.pricing.period).quantize(Decimal('1.00'))
  
          raise ValueError('Plan %s has no pricings.' % plan)
docs: Finds most fitted plan pricing for a given period, and calculate day cost