Bala kumar
unread,Jul 1, 2009, 7:16:18 AM7/1/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django developers
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?