Hi,
Is it possible to apply validation on particular field within
models.py?.
I have the below model defined, the form is dynamically managed by
Django Admin
class CategoryMapping(models.Model):
categoryid = models.AutoField(primary_key=True,)
categorytype = models.CharField( max_length = 250, unique =
True,)
displayname = models.CharField( max_length = 250, blank =
False,)
description = models.TextField( blank = True,)
def __str__(self):
return self.categorytype
class Meta:
db_table = 'category_mapping'
Here I want to apply a validation for the field 'categorytype' in
models.py itself without calling forms.py
eg:
def clean_categorytype(self):
if self.cleaned_data.get('categorytype', 'test'):
raise forms.ValidationError(u'Please enter valid category
type')
else:
return self.cleaned_data.get('categorytype')
is it possible?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" 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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---