OK, got it working:
changed view code to:
 if request.method =='POST':
        form = AppUserForm(request.POST,request.FILES)

On Dec 15, 2:48 pm, rtmie <robm...@yahoo.com> wrote:
> H i ,
> I am trying to migrate a project from 0.95 to 1.02 and so have to
> migrate all of my old model based validator stuff in the new forms
> style( my first encounter with the new forms style).
>
> I am having a problem with the following:
>
> in my model I have a AppUser class, with username , password , email
> etc and I have a requirement that the username be unique , regardless
> of case. I have a valifdation funtion to check this and raise a
> ValidationError,
> however when I call it with a duplicate name via form.isValid() I get
> a return value of False (i.e validation failed as expected) BUT the
> form.errors list is empty. I am obviously doing something dumb, but
> can't for the life of me figure it out.
>
> Model:
>
> class AppUser(models.Model):
>     name = models.CharField(_('name'),
>                             max_length=100,
>                             db_column='name',
>                             unique=True)
>     email = models.EmailField(_('email'),
>                              db_column='email',
>                              blank=True,
>                              max_length=320)
>     password = models.CharField(_('password'),
>                                 max_length=30,
>                                 db_column='password')
>
> Form:
> class AppUserForm(ModelForm):
>     class Meta:
>         model = AppUser
>
>     def clean_name(self):
>         name = self.cleaned_data["name"]
>         if self.instance.id:
>             cps = AppUser.objects.exclude(id__exact=self.instance.id)
>         else:
>             cps = AppUser.objects.all()
>             for index in range(0,len(cps)):
>                 if upper(cps[index].name) == upper(name):
>                     raise forms.ValidationError, "App user name must
> be unique, regardless of \
> case"
>         return name
>
> View:
>
> def createUser(request):
>     form = AppUserForm()
>     if request.method =='POST':
>         form.data = request.POST
>         if form.is_valid():
>             log.debug("saving valid user")
>             cp   = form.save(True)
>         else:
>             log.error( form.errors)
> log.error("error list: %s" , str(form.errors))
>             log.error("failed  App User validation ")
>
> log output
> app        2008-12-15 14:46:26,384 [ERROR] error list:
> app        2008-12-15 14:46:26,384 [ERROR] failed  CP validation
--~--~---------~--~----~------------~-------~--~----~
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