On Jun 24, 12:40 am, saxon75 <saxo...@gmail.com> wrote: > I'm having a strange problem with my site wherein a ModelForm doesn't > appear to recognize that it has an attribute that it ought to. I > should preface this by saying that I recently moved my codebase to a > new server--everything had been working fine on the old server and I > haven't made any changes to the code since then, so that seems like > the only thing that could have changed, but I have no idea what the > problem is. > > In any case, here are the relevant bits of code:
<snip> > def add_article(request, sect): > if request.user.is_authenticated(): > if request.user.is_superuser or request.user.groups.filter > (name=sect).count(): > if request.method == 'POST': > form = AddArticleForm(request.POST) > if not form.slug: > form.slug = slugify(form.title) > if form.is_valid(): > article = form.save(commit=False) > article.author = request.user > article.created = datetime.now() > article.section = Section.objects.get(keyword=sect) > article.save() > return render_to_response('thanks.html', > context_instance=RequestContext(request)) <snip> > The error comes up in views.py from the add_article() method, the line > "if not form.slug:" The error itself is: 'AddArticleForm' object has > no attribute 'slug' > > This is pretty odd to me, since it seems clear to me from the > declaration that AddArticleForm does have that attribute. Further, > this used to work. > > I am in the HEAD revision of django as of a few minutes ago, and my > Python version is 2.5.4. Actually, now that I think of it, I may have > been using Python 2.4 on the old server. Could that be the problem? You can't access the values of form fields via attribute lookup. Instead, after checking form.is_valid(), you should get the value of slug via form.cleaned_data['slug']. I can't explain why what you were doing used to work, but it shouldn't. -- DR. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---