thinwybk
thinwybk

Reputation: 4743

Django FilePathField raises file not found error

I've defined a Django model which makes use of FilePathField(allow_files=False, allow_folders=True) which shall allow to define a required (not optional) file system directory in the model. If I try to add a new model in the admin interface I get a file not found error. All my other models registered the same way are just working fine. If I'd use CharField() instead of FilePathField() to hold the file system directory path I'd simply define a default value like CharField(default='').

How can I fix the model making use of the FilePathField field?

Upvotes: 2

Views: 877

Answers (1)

Zelo
Zelo

Reputation: 332

I have encountered same problem and the cause of the error is that django tries to scan the directory in order to get list of files that will be displayed as choices in html widget. There are few solutions.

  • If you don't mind limiting what paths can be added by users just add path=/some/dir to FilePathField
  • If you don't want to limit paths but don't care about ability to update path trough admin just set editable=False in FilePathField
  • If you want both you can replace widget in admin for this particular field to classic text input.

Upvotes: 3

Related Questions