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!
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With