title: Django South: How to create rules for a Custom Field?
body: <p>I've create a custom field "Private FileField". I'm not able to get it to work with django-south.</p>
  
  <p>My understanding of South field rules is based on
  <a href="http://south.aeracode.org/docs/tutorial/part4.html#tutorial-part-4" rel="nofollow noreferrer">http://south.aeracode.org/docs/tutorial/part4.html#tutorial-part-4</a> and
  <a href="http://south.aeracode.org/docs/customfields.html" rel="nofollow noreferrer">http://south.aeracode.org/docs/customfields.html</a></p>
  
  <p>Relevant snippets are:</p>
  
  <pre><code>class FileField(models.CharField):
      __metaclass__ = models.SubfieldBase
  
      def __init__(self, *args, **kwargs):
          if not 'upload_to' in kwargs:
              raise Exception("%s expects one keyword arg 'upload_to'" % (self.__class__))
          self.upload_to = kwargs['upload_to']
          del kwargs['upload_to']
          kwargs['max_length'] = 255
          super(FileField, self).__init__(*args, **kwargs)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>rules = [
    (
      (FileField,),
      [],
      {
          "upload_to": ["upload_to", {}],
      },
    )
  ]
  
  from south.modelsinspector import add_introspection_rules
  add_introspection_rules(rules, ["^private_filefield\."])
  </code></pre>
  
  <p>Running a manage.py schemamigration my_app_name --auto fails with the following message:</p>
  
  <p><code>Exception: &lt;class 'private_filefield.fields.FileField'&gt; expects one keyword arg 'upload_to'</code></p>
  
  <p>(this happes when site-packages/south/orm.py", line 46, in FakeORM is called)</p>
  
  <p>Full code can be found on:
  <a href="http://bitbucket.org/vanschelven/django_private_filefield/src/tip/private_filefield/fields.py" rel="nofollow noreferrer">http://bitbucket.org/vanschelven/django_private_filefield/src/tip/private_filefield/fields.py</a></p>
  
  <p>=== Edit: text below added ===</p>
  
  <p>This is the relevant section of the generated 'models' section of the auto-generated migration:</p>
  
  <pre><code>    'mailfile.mailfile': {
          'Meta': {'object_name': 'MailFile'},
          'creation_date': ('django.db.models.fields.DateField', [], {'auto_now_add': 'True', 'blank': 'True'}),
          'expires_on': ('django.db.models.fields.DateField', [], {'default': 'datetime.date(2010, 7, 16)'}),
          'file': ('private_filefield.fields.FileField', [], {'max_length': '255'}),
          'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
          'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
          'secret': ('django.db.models.fields.CharField', [], {'max_length': '40'})
      }
  </code></pre>
  
  <p>Note the lack of 'upload_to' as paramter to 'file'.</p>