Hi Folks,
I am wrote a simple application in djang0 1.0.2 to check the custom
validation. I will past the model.py and admin.py code here.
model.py
-----------
from django.db import models
from django.contrib import admin
from django import forms
class Personal(models.Model):
firstName = models.CharField(
max_length = 20,
blank = True,
null = True,
)
age = models.IntegerField(
blank = True,
null = True,
)
salary = models.DecimalField(
max_digits = 7,
decimal_places = 2,
admin.py
-----------
from MyApp.Personal.models import Personal
from django.contrib import admin
from django import forms
from django.forms import ValidationError
class DocumentValidationError(forms.ValidationError):
def __init__(self):
super(DocumentValidationError, self).__init__(_(u'Document
types accepted: ') + ', '.jo\
in(salary.valid_file_extensions))
class PersonalForms(forms.ModelForm):
model=Personal
default_err_msg = {'invalid':u'Salary cannot be negetive',}
def clean(self):
super(PersonalForms,self).clean()
salary = self.cleaned_data['salary']
if salary is not None and float(salary) < 0:
raise forms.ValidationError(self.default_err_msg
['invalid'])
return self.cleaned_data
class PersonalAdmin(admin.ModelAdmin):
form = PersonalForms
search_fields = ['email']
If salary is found negative it displays the error message in beginning
of the form(that is after the message 'Please correct the error below.
'). Actually it should display the error message in the 'Salary'
section
I think, I am missing something here.
Can anyone help?
Thanks and Best Regards
Harish Bhat M
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---