Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative upload method for Django FileField

I have some django models that use a FileField, and users have been uploading files in the admin interface. We now have a problem that some files are quite big (1-3G), which makes http upload tricky.

There is a "container" class, and then "file" classes with a FK to the container. I have used inlines in the admin gui to make this easier for the users (container class form, with file class inlines)

I have found FilePathField, which I guess will be useful to let users scp / rsync files over to the server and then browse for and add details to them, but how can I get this in the admin? Do I need to just build a new form / view that creates the objects? Is there any way to somehow override the model in a custom admin form (and thus keep all the free admin goodness), that replaces filefield with filepathfield? Any other suggestions?

Thanks for any suggestions!

like image 747
user130924 Avatar asked Aug 11 '09 15:08

user130924


1 Answers

You mention that FilePathField works, but needs to have the webserver restarted to see new files. This happens because the options are gathered FilePathField.__init__, which is called once when the module is imported.

A fix would be to re-call the field's __init__ in the form's __init__:

def __init__(self, **kwargs):
    super(MyForm, self).__init__(**kwargs)
    self.fields['file'].__init__(path)

(That way the directory is scanned each time the form is instanced.)

like image 129
Matthew Marshall Avatar answered Oct 19 '22 20:10

Matthew Marshall