Django South: How to create custom field rules?

I created a "Private FileField" custom field. I can't get him to work with the 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 fragments:

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\."])

Run control file. my_app_name --auto failed to execute the following message:

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

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

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

=== Edit: the text below is added ===

"" :

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

"upload_to" "".

+3
1

, , .

Django . . FileField schemamigration --auto . , , .

, , , upload_to? ( , , ).

+1

Source: https://habr.com/ru/post/1752823/


All Articles