title: Django Custom Field - Boolean -> CHAR YN
body: <p>Due to a legacy system I'm trying to get Django boolean fields to save in the dB as a simple 'Y' or 'N' char field (VARCHAR not supported in said legacy system).</p>
  <p>Using a django custom field I have it working but struggling to get Django admin to work with the field.</p>
  <pre><code>class BooleanYN(models.BooleanField):
      &quot;&quot;&quot; We need to save boolean variables as CHAR Y/N 
  
      &quot;&quot;&quot;
  
      description = _(&quot;Boolean field stored as Y or N in the dB&quot;)
  
      def from_db_value(self, value, expression, connection):
          if value in ('Y', 'y'):
              return True
          if value in ('N', 'n'):
              return True
          raise ValidationError(_(f&quot;Value in dB is not Y or N - {value}&quot;))
  
      def get_prep_value(self, value):
          if value is True:
              return 'Y'
          if value is False:
              return 'N'
          return value
  
      def db_type(self, connection):
          return char(1)
  </code></pre>
  <p>In Django admin, single record view + list view, the checkbox widget is always flagged as true even though 'N' is correctly saved in the dB and &quot;to_python&quot; is correctly being passed 'False' or 'True' as the value when its called by the modelform code depending on whether 'Y' or 'N' in the dB.</p>
  <p>Any help appreciated!</p>