The error is natural, given that during the evaluation
file = models.FileField(upload_to=UploadItem.get_directory)
class UploadItemis not defined yet. You can do the following to make it work:
def get_directory():
pass
class UploadItem(models.Model):
file = models.FileField(upload_to=get_directory)
class Meta:
abstract = True
This will not solve all your problems. Adding (or overriding) a method get_directoryin a class Videowill not change the upload_toattribute property of the filemodel.
Refresh
, upload_to .
, , , , . Unix ( ), .
, :
categories_and_paths = { 'video': 'videos/', 'photo': 'photos/' }
def get_directory(instance, filename):
category = instance.category
return categories_and_paths.get(category, '')
Instance . . .
class Video(UploadItem):
category = 'video'