title: how to create a tariff calculator in django?
body: <p>basically i'm creating a tariff calculator for a utility company in my country, based on a progressive rates table, an example given below</p>
  
  <p>2.(a) In any one month for less than 1,001 gallons a fee of ………………………..… $9.23</p>
  
  <p>(b) Proportionate fee for every gallon thereafter up to 2,000 gallons inclusive at the rate per 1,000 gallons of ………………..$15.89</p>
  
  <p>(c) Proportionate fee for every gallon above 2,000 gallons and up to 3,000 gallons inclusive at the rate per 1,000 gallons of .………..$17.43</p>
  
  <p>(d) Proportionate fee for every gallon above 3,000 gallons and up to 4,000 gallons inclusive at the rate per 1,000 gallons of .………..$18.45</p>
  
  <p>(e) Proportionate fee for every gallon above 4,000 gallons and up to 5,000 gallons inclusive at the rate per 1,000 gallons of .………..$19.48</p>
  
  <p>(f) Proportionate fee for every gallon above 5,000 gallons and up to 6,000 gallons inclusive at the rate per 1,000 gallons of .………..$20.50</p>
  
  <p>(g) Proportionate fee for every gallon above 6,000 gallons and up to 7,000 gallons inclusive at the rate per 1,000 gallons of .………..$21.01</p>
  
  <p>(h) Proportionate fee for every gallon above 7,000 gallons and up to 8,000 gallons inclusive at the rate per 1,000 gallons of .………..$21.53</p>
  
  <p>(i) Proportionate fee for every gallon above 8,000 at the rate per 1,000 gallons of ...$22.04</p>
  
  <p>I'm thinking of doing a Rate model with the following fields:</p>
  
  <ol>
  <li>area of supply</li>
  <li>description</li>
  <li>from_gallons (starting range of gallons)</li>
  <li>to_gallons (end range of gallons)</li>
  <li>rate_per_1000g </li>
  </ol>
  
  <p>my view would accept post from a form with the amount of gallons, area of supply and should post back the usage calculated from the rate table.</p>
  
  <p>i would do something like this in the view</p>
  
  <pre><code>from models import Rate    
  def tarrif_calc(request,gallons,area):
      rate = Rate.objects.get(area_of_supply=area, from_gallons &gt;= gallons, to_gallons &lt;= gallons)
      rate_per_gal = rate.rate_per_1000g/1000
      usage = gallons * rate_per_gal
      return usage
  </code></pre>
  
  <p>this is the most simple e.g i can think of, however i'm not sure how i would handle the progressive rates... any ideas? am i on the right track?</p>