title: Django default model properties based on existing property values?
body: <p>I have a simple data model in Django, with classes <code>Department</code> and <code>Role</code>. (For example sake.)</p>
  
  <p>A <code>Department</code> has a one-to-many relationship with <code>Role</code>, and the <code>Role</code> class contains an ID that is being used to identify particular instances. For example:</p>
  
  <pre><code>&gt; Department: Sales
  &gt;&gt; Role (1): Accounts
  &gt;&gt; Role (3): Closing
  
  &gt; Department: Maintenance
  &gt;&gt; Role (2): IT
  &gt;&gt; Role (4): Equipment
  </code></pre>
  
  <p>The downside to this is that each role is using its own <em>global</em> ID. So if you were to create a large number of Sales roles, and then create an additional Maintenance role, that new Maintenance role would have an incredibly large ID, and would seem "out-of-sync."</p>
  
  <p>Thus, I would like to create a <strong>department-specific ID for each Role</strong> as well, like so:</p>
  
  <pre><code>class Role(models.Model):
      department_id = models.IntegerField()
  </code></pre>
  
  <p>The downside is that I can't find a way to either:</p>
  
  <p>1)  Have existing Roles transfer their existing IDs to the new <code>department_id</code> field, leaving the gaps but preventing future gaps from appearing:</p>
  
  <pre><code>&gt; Department: Sales
  &gt;&gt; Role (1): Accounts
  &gt;&gt; Role (3): Closing
  &gt;&gt; Role (4): *New Sales Role*
  
  &gt; Department: Maintenance
  &gt;&gt; Role (2): IT
  &gt;&gt; Role (4): Equipment
  &gt;&gt; Role (5): *New Maintenance Role*
  </code></pre>
  
  <p>2) Or, dynamically assign the <code>default</code> value to a method that scans the table for all the Roles of each department, and assigns them new IDs:</p>
  
  <pre><code>&gt; Department: Sales
  &gt;&gt; Role (1): Accounts
  &gt;&gt; Role (2): Closing
  &gt;&gt; Role (3): *New Sales Role*
  
  &gt; Department: Maintenance
  &gt;&gt; Role (1): IT
  &gt;&gt; Role (2): Equipment
  &gt;&gt; Role (3): *New Maintenance Role*
  </code></pre>
  
  <p>I'm using South to handle schema migrations.</p>