Django ModelAdmin custom method obj parameter
<p>In Django's document 
<a href="https://docs.djangoproject.com/en/1.10/ref/contrib/admin/" rel="nofollow">Django Document</a></p>

<p>It has following code.</p>

<pre><code>from django.contrib import admin

class AuthorAdmin(admin.ModelAdmin):
    fields = ('name', 'title', 'view_birth_date')

    def view_birth_date(self, obj ):
        return obj.birth_date

    view_birth_date.empty_value_display = '???'
</code></pre>

<p>I don't understand in the custom method view_birth_date(self, <strong><em>obj</em></strong> ) where this obj parameter came from?</p>

<p>Note in the last line, it called this function, </p>

<pre><code>view_birth_date.empty_value_display = '???'
</code></pre>

<p>but did not pass any parameter for obj. I don't understand where how obj got a value.</p>

<p>Thanks!</p>

<blockquote>
  <p>I don't understand in the custom method <code>view_birth_date(self, obj)</code> where this <code>obj</code> parameter came from?</p>
</blockquote>

<p>This method is called by Django's machinery and <code>obj</code> is passed also by it. It's just a predefined interface.</p>

<blockquote>
  <p><code>view_birth_date.empty_value_display = '???'</code> 
  but did not pass any parameter for obj. I don't understand where how <code>obj</code> got a value.</p>
</blockquote>

<p>This line has nothing to do with your question. Again, according to the interface, Django when looking at your method (function) looks for <code>empty_value_display</code> attribute to find out what value the developer expects to see when the current value is empty.</p>

<p>Yes, looks weird but it's just how Django works, how its creators made it work. They chose this interface -- you just have to use the docs to find out the interface.</p>

python django