Admin.py
class CourseAdmin(admin.ModelAdmin):
list_display = ('course_code', 'title', 'short' )
def save_model(self, request, obj, form, change):
import os
#obj.author = request.user
dir_name = obj.course_code
path = settings.MEDIA_ROOT +os.sep+'xml'+os.sep+dir_name
#if user updates course name then course would be renames
if change:
dir_name = Course.objects.get(pk=obj.pk).course_code
src = settings.MEDIA_ROOT +os.sep+'xml'+os.sep+dir_name
os.rename(src,path)
else:
if not os.path.exists(path):
os.makedirs(path)
obj.save()
else:
raise ValidationError('Bla Bla')
admin.site.register(Course, CourseAdmin)
when i raise validation Error it doesn't work and shows error page with Exception Type: Validation Error Exception Value:[u'Bla Bla']
Here's an example:
def clean_name(self): if something: raise forms.ValidationError("Something went wrong") return self.cleaned_data["name"]
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