title: Django: Creating a Mixin for Reusable Model Fields
body: <p>I've got a few fields that I want to add to most every model in my project.  For example, these fields are "tracking fields" such as a created date, an update date, and an "active" flag.  I'm attempting to create a Mixin that I could add to each model class that would allow me to add these extra fields via multiple inheritance.  However, when an object instance is created, it appears that my model fields that were added via the Mixin show up as methods of the object rather than database fields.  </p>
  
  <pre><code>In [18]: Blog.objects.all()[0].created
  Out[18]: &lt;django.db.models.fields.DateTimeField object at 0x10190efd0&gt;
  </code></pre>
  
  <p>Here is what my models look like: </p>
  
  <pre><code>from django.db import models
  
  class Blog(models.Model, TrackingFieldMixin):
      name = models.CharField(max_length=64)
      type = models....
  
  
  class TrackingFieldsMixin():
  
      active = models.BooleanField(default=True, 
          help_text=_('Indicates whether or not this object has been deleted.'))
      created = models.DateTimeField(auto_now_add=True)
      modified = models.DateTimeField(auto_now=True)
  
      class Meta:
          abstract = True
  </code></pre>
  
  <p>So this doesn't appear to work.  Does anyone know how I am able to create a reusable mixin for common model fields similar to above?  Is there a flaw in this approach?</p>
  
  <p>Thanks for you help,
  Joe</p>
  
  <p>Update: Note that some of my models that I plan to use the mixin in use the MPTT model, so I can't simply make my TrackingFieldMixin mixin the base class and inherit only from it. </p>
  
  <pre><code>class Post(MPTTModel, TrackingFieldMixin):
      post_name = models....
      post_type = models...
  </code></pre>