views:

29

answers:

0

I've create a custom field "Private FileField". I'm not able to get it to work with django-south.

My understanding of South field rules is based on http://south.aeracode.org/docs/tutorial/part4.html#tutorial-part-4 and http://south.aeracode.org/docs/customfields.html

Relevant snippets are:

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)

and

rules = [
  (
    (FileField,),
    [],
    {
        "upload_to": ["upload_to", {}],
    },
  )
]

from south.modelsinspector import add_introspection_rules
add_introspection_rules(rules, ["^private_filefield\."])

Running a manage.py schemamigration my_app_name --auto fails with the following message:

Exception: <class 'private_filefield.fields.FileField'> expects one keyword arg 'upload_to'

(this happes when site-packages/south/orm.py", line 46, in FakeORM is called)

Full code can be found on: http://bitbucket.org/vanschelven/django_private_filefield/src/tip/private_filefield/fields.py

=== Edit: text below added ===

This is the relevant section of the generated 'models' section of the auto-generated migration:

    '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'})
    }

Note the lack of 'upload_to' as paramter to 'file'.