title: Django model field default based on another model field
body: <p>I use Django Admin to build a management site. There are two tables, one is <code>ModelA</code> with data in it, another is <code>ModelB</code> with nothing in it. If one model field <code>b_b</code> in <code>ModelB</code> is None, it can be displayed on the webpage with the value of <code>ModelA</code>'s field <code>a_b</code>.</p>
  
  <p>I don't know how to do it, Here is the pseudo code:</p>
  
  <p>In models.py</p>
  
  <pre><code>from django.db import models
  
  class ModelA(models.Model):
    a_a = models.CharField(max_length=6)
    a_b = models.CharField(max_length=6)
  
  class ModelB(models.Model):
    modela = models.OneToOneField(ModelA)
    b_b = models.CharField(max_length=6, choices=[(1, 'M'), (2, 'F')], default=self.modela.a_b)
  </code></pre>
  
  <p>In admin.py</p>
  
  <pre><code>from django.contrib import admin
  from .models import ModelA, ModelB
  
  class ModelBAdmin(admin.ModelAdmin):
    fields = ['b_b']
    list_display = ('b_b')
  </code></pre>
  
  <p>I think if b_b of modelB have default value of relative a_b value of modelA, I have a default value of b_b(View) in the django admin change(edit) page which associate data to a particular modelB instance.</p>
  
  <p>I want to fill b_b in web page more easily.</p>
  
  <p>I don't know whether this requirement can be achieved? Or there is another way can achieve this?</p>
  
  <p>I try to custom the templates filter as following:</p>
  
  <p>In templates/admin/includes/fieldset.html</p>
  
  <pre><code> {% load drop_null %}
  
      {% if field.is_checkbox %}
          {{ field.field }}{{ field.label_tag }}
      {% else %}
          {{ field.label_tag }}
          {% if field.is_readonly %}
              &lt;p&gt;{{ field.contents }}&lt;/p&gt;
          {% else %}
              {% if field.field.name == 'b_b' %}
                  {{ field|dropnull }}
              {% else %}
                  {{ field.field }}
              {% endif %}
          {% endif %}
      {% endif %}
  </code></pre>
  
  <p>In templatetags/drop_null.py</p>
  
  <pre><code>from django import template
  register = template.Library()
  
  @register.filter(name='dropnull')
  def dropnull(cls):
      return cls.modela.a_b
  </code></pre>
  
  <p>The 'field' is &lt; django.contrib.admin.helpers.AdminField object at 0x3cc3550> . It is not an instance of ModelB.
  How can I get ModelB instance?</p>