Hi all,
In the admin.py code of my project, I have an override to a save() method
where I check a file upload's extension and, based on that,
should either save the instance object or update show an error message on
the admin form as follows:
def save_model(self, request, obj, form, change):
try:
file_name = request.FILES['audio_file'].name
if file_name.split('.')[1] == 'mp3':
obj.save()
else:
raise forms.ValidationError("The podcast file must be of
type .mp3")
except:
raise forms.ValidationError("A podcast file is required.")
The issue is that when a forms.ValidationError is raised as expected, I am
getting a stack trace instead of the error message being displayed on the
form.
I do have debug set to True in my settings as this is a development
environment, but how can I cause the errors to be displayed on the form
instead of a stack trace as follows?:
ValidationError at /admin/browse/podcast/add/
[u'A podcast file is required.']
Request Method: POST Request URL:
http://127.0.0.1:8000/admin/browse/podcast/add/ Django Version: 1.2.3
Exception
Type: ValidationError Exception Value:
[u'A podcast file is required.']
Exception Location:
C:\Websites\TPFRepository\thepokerfarm\..\thepokerfarm\browse\admin.py
in save_model, line 212 Python Executable: C:\Python26\python.exe Python
Version: 2.6.5
...etc
Thanks!
--
Regards,
Sithembewena Lloyd Dube
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.