Hi Folks,

I have implemented a simple custom validator. Here i am pasting the
Code
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']


Now my question is, Can we use the same validator for validating
another field.

In previous django versions (0.97) I was able to use the same
validators for validating two or more fields. Is it possible with the
django 1.0.x because we don't  have 'validators_list' property in
models. In Django 1.0.x models and model admin are separated.

here my basic question is (if i am not wrong)why django is not using
the DRY (Dont Repete Yourself) principle with respect to
validators...

Can anybody explain to me if at all I am wrong.

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

Reply via email to