JDavies
JDavies

Reputation: 2770

TypeError: __init__() got an unexpected keyword argument category

I'm creating a basic app where my client can upload files through the app. It will then provide them with a URL so they can add images/pdf's etc to content in the website. What i'd like to do is have different category choices so when they upload a file they select the file type. So if they select 'images' the files will be uploaded into the images directory, and so on.

Here is my code so far, i've gone to run python manage.py syncdb to add the models to the database but getting the above error.

CATEGORY_CHOICES = (
        ('Image', 'Image'),
        ('PDF', 'PDF')
    )

file_type = models.CharField(category=CATEGORY_CHOICES, help_select="Please select a file type", default=IMAGE)
file_upload = models.FileField(upload_to="media/images")

def save(self, *args, **kwargs):    
    if self.file_type == 'Image':
        self.file.upload_to("media/images/filesApp")
    elif self.file_type == 'PDF':
        self.file.upload_to("media/pdf/filesApp")
    else:
        self.file.upload_to("media/filesApp")

    return super(File,self).save(*args, **kwargs)

Upvotes: 1

Views: 6819

Answers (1)

karthikr
karthikr

Reputation: 99640

In your form,

file_type = models.CharField(category=CATEGORY_CHOICES, help_select="Please select a file type", default=IMAGE)

category=CATEGORY_CHOICES

should be

choices=CATEGORY_CHOICES

Upvotes: 5

Related Questions