title: Problem with custom primary key in Django
body: <p>In the following model (<code>Item</code>) my goal is to define a customized object ID explicitly when saving. I'm using Django 1.2.5 and sqlite.</p>
  
  <pre><code>class Category(models.Model):
      name = models.CharField(max_length=32)
  
  class Item(models.Model):
      id = models.CharField(primary_key=True, blank=True, max_length=8)
      group = models.ForeignKey(Category)
  
      def save(self, *args, **kwargs):
          self.id = "%s-%s" % (self.group.id, self.group.item_set.count() + 1)
          super(Item, self).save(*args, **kwargs)
  </code></pre>
  
  <p>I have the problem that using the admin interface for Item model, when I'm going to save an object that already exists, instead of update the existing record a new record is created. I tried to force the update when appropriate with this code</p>
  
  <pre><code>def save(self, *args, **kwargs):
      update = bool(self.id)
      self.id = "%s-%s" % (self.group.id, self.group.item_set.count() + 1)
      super(Item, self).save(force_update=update, *args, **kwargs)
  </code></pre>
  
  <p>but without success. Now saving after a change triggers this other problem:</p>
  
  <pre><code>DatabaseError at /admin/type/catalog/1_3/
  
  Forced update did not affect any rows.
  </code></pre>
  
  <p>I'd like to know what I'm doing wrong and if there is a way to solve the issue.</p>
  
  <p>Thanks</p>
  
  <p>-- EDIT -- (need more help!)</p>
  
  <p><strong>Use case.</strong></p>
  
  <p>I want to obtain that when a category is selected, only the items that belongs to that category are shown in the items select box.</p>
  
  <p>For this reason I need to associate each item to the corresponding category using the id field, so that categories and items in the admin interface, if together in the same page, would be relationated by their id (and thus easily handled using jQuery). This way:</p>
  
  <pre><code>&lt;select id="id_category" name="category"&gt;
    &lt;option value="1"&gt;color&lt;/option&gt;
    &lt;option value="2"&gt;car&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;select id="id_item" name="item"&gt;
    &lt;option value="1_1"&gt;red&lt;/option&gt;
    &lt;option value="1_2"&gt;blue&lt;/option&gt;
    &lt;option value="2_1"&gt;audi&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>If I would use another field but id, combobox in admin would be totally unrelated in respecet if their id, because item select would be:</p>
  
  <pre><code>  &lt;option value="1"&gt;red&lt;/option&gt;
    &lt;option value="2"&gt;blue&lt;/option&gt;
    &lt;option value="3"&gt;audi&lt;/option&gt;
  </code></pre>
  
  <p>Hope I've been clear enough!</p>