List Info

Thread: Validation of files uploaded via an admin form




Validation of files uploaded via an admin form
user name
2007-01-28 14:16:38
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


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )