title: Django creating a custom model field
body: <p>I am trying to create a custom field in Django which will take a decimal currency value (example: £1.56) and save it in the database as an Integer (example: 156) to store currency values.</p>
  
  <p>This is what I have so far (I have put fixed values to test)</p>
  
  <pre><code>class CurrencyField(models.DecimalField):
      __metaclass__ = models.SubfieldBase
  
      def get_internal_type(self):
          return 'PositiveIntegerField'
  
      def to_python(self, value):   
          print "CurrentField to_python"
  
          return Decimal(value)/100
  
      def get_db_prep_value(self, value, connection, prepared=False):
          print "CurrentField get_db_prep_value"
          if value is None:
              return value
  
          print type(value)
  
          return int(value*100)
  </code></pre>
  
  <p>I am following the <a href="https://docs.djangoproject.com/en/1.7/howto/custom-model-fields/" rel="noreferrer">Python 1.7 documentation for creating custom model fields</a>. </p>
  
  <p>In the above code, the <code>get_db_prep_value</code> method is never being called when I save the model using this field. The <code>to_python</code> method is working fine (if I manually enter the value in the DB it will return the correct decimal), however it will never save the correct value.</p>
  
  <p>I have also tried using <code>get_prep_value</code> and this has the same result.</p>
  
  <p>How can I make it save the correct value?</p>