I have a model that takes in multiple pdf files. When users upload these files, I'd like each file to be renamed with a prefix and some random characters. I can assign the upload\_to to callable functions, example:

```
class Order(models.Model):
    invoice_file = models.FileField(upload_to=invoice_file_name)
    purchase_order_file = models.FileField( upload_to=po_file_name)
    payment_file = models.FileField( upload_to=payment_file_name)

def invoice_file_name(instance, file_name):
    return 'inv_' + str(uuid.uuid4()) + '.pdf'

def po_file_name(instance, file_name):
    return 'po_' + str(uuid.uuid4()) + '.pdf'

def payment_file_name(instance, file_name):
    return 'pmt_' + str(uuid.uuid4()) + '.pdf'

```

Is there a way to generalize these upload\_to functions so I can pass the prefix in the FileField definition?

**ATTEMPT:**

I attempted to solve this by creating a custom file field that extends FileField

```
class CustomFileField(models.FileField):
    def __init__(self, file_prefix, **kwargs):
        self.file_prefix = file_prefix
        # print(kwargs)
        super().__init__(upload_to=self.custom_upload_to, **kwargs)

    def custom_upload_to(self, file_name):
        return self.file_prefix + str(uuid.uuid4()) + '.pdf' 

class Order(models.Model):
    invoice_file = CustomFileField(file_prefix='inv_')
    purchase_order_file = CustomFileField(file_prefix='po_')
    payment_file = CustomFileField(file_prefix='pmt_')

```

However, the migrations failed. One of the errors is 

```
TypeError: __init__() got multiple values for keyword argument 'upload_to'

```

Not quite sure what's going on but I looked at the migration file and it seems to be calling this:

```
migrations.CreateModel(
    name='Order',
    fields=[
        ('invoice_file', CustomFileField(blank=True, null=True, upload_to='')
        ...
    ])

```

Is this the wrong way to subclass FileField?