On 3 Nov., 16:34, Bülent Aldemir <[EMAIL PROTECTED]> wrote:
> Create methods with <clean_fieldname> like:
>
> class MyModel(models.Model):
> mystring = models.CharField(max_length=100)
>
> class MyForm(forms.ModelForm):
> def clean_mystring(self):
> raise forms.ValidationError('Error Message')
>
Thanks a lot! It works.
It even works with __getattr__, so i do not have to create a subclass
for
every model.
class MyForm(forms.ModelForm):
def do_authorisation(self, name):
print self.Meta.model._meta.verbose_name
#raise forms.ValidationError('Error Message')
return self.cleaned_data[name]
def __getattr__(self, name):
print name
if name[:6] == 'clean_':
return lambda: self.do_authorisation(name[6:])
Greets,
Sebastian
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---