Validation of files uploaded via an admin form

3 views
Skip to first unread message

gene...@googlemail.com

unread,
Jan 28, 2007, 3:16:38 PM1/28/07
to Django users
Hi, I'm having a little difficulty with validating a file which is
uploaded by the user in the admin centre. Basically, I've created a
small model which stores data about a music file upload. The
documentation for FileField (which I'm using) says (I quote):
'Validate all uploaded files so that you're sure the files are what
you think they are...'

However, I can't get this to work. I have created a custom validator,
which checks whether the filetype is of mp3 or ogg, and that the
extension is 'mp3' or 'ogg'. This works fine for the initial upload
(and indeed I can upload files!), but when I go to the 'edit' part of
the admin and upload a new file, I get a TypeError. This is because in
my validator, I check the field_data the first time for 'filename' and
'content-type', because field_type is a dictionary, but it seems that
on an edit, field_type is a string with the filename of the _previous_
file which was uploaded. Why?!

Anyway, my question is: how can I complete this (seemingly) relatively
simple task of validation?

Here's my code so far: http://dpaste.com/5068/

Any help would be much appreciated.

--
Isaac

Reply all
Reply to author
Forward
0 new messages