title: Django Model Field Default Based Off Another Field in Same Model
body: <p>I have a model that I would like to contain a subjects name and their initials (he data is somewhat anonymized and tracked by initials).</p>
  <p>Right now, I wrote</p>
  <pre><code>class Subject(models.Model):
  
      name = models.CharField(&quot;Name&quot;, max_length=30)
      def subject_initials(self):
          return ''.join(map(lambda x: '' if len(x)==0 else x[0],
                             self.name.split(' ')))
      # Next line is what I want to do (or something equivalent), but doesn't work with
      # NameError: name 'self' is not defined
      subject_init = models.CharField(&quot;Subject Initials&quot;, max_length=5, default=self.subject_initials)
  </code></pre>
  <p>As indicated by the last line, I would prefer to be able to have the initials actually get stored in the database as a field (independent of name), but that is initialized with a default value based on the name field.  However, I am having issues as django models don't seem to have a 'self'.</p>
  <p>If I change the line to <code>subject_init = models.CharField(&quot;Subject initials&quot;, max_length=2, default=subject_initials)</code>, I can do the syncdb, but can't create new subjects.</p>
  <p>Is this possible in Django, having a callable function give a default to some field based on the value of another field?</p>
  <p>(For the curious, the reason I want to separate my store initials separately is in rare cases where weird last names may have different than the ones I am tracking.  E.g., someone else decided that Subject 1 Named &quot;John O'Mallory&quot; initials are &quot;JM&quot; rather than &quot;JO&quot; and wants to fix edit it as an administrator.)</p>