I upgraded this morning from Django 1.1.1 (r11312, I think) to the
most recent HEAD revision (r11794) and it appears that some changes
have been made to the form validation scheme again.  I have a blog app
wherein I want the application to be able to automatically generate
slugs from post titles.  Previously, I had used something like this in
the "add blog post" view:

if request.method=='POST':
  form = AddArticleForm(request.POST)
  if form.is_valid():
    article = form.save(commit=False)
    if not form.cleaned_data['slug']:
      article.slug = slugify(form.cleaned_data['title'])[:
25].rstrip('-')
    article.save()

And this worked pretty nicely.  Now, however, when I try to submit a
form with a blank "slug" field, I get redirected back to the form with
a notice that I need to fill in that field.

I tried overriding the Article model's clean() function like so:

def clean(self):
  if not self.slug:
    self.slug = slugify(self.title)[:25].rstrip('-')

That didn't help the problem.  So, where's the right place to put this
code?  New custom validate() function in the form class?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" 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-users?hl=en.

Reply via email to