Alex - you are a legend. That's functioning perfectly. I've moved the
import line to the start of the file, but other than that used your
code and it's working a treat.

Thanks for the swift help Alex, and also Karen: together you've
clarified Django very clearly for me.

On Jan 6, 6:01 pm, "Alex Koshelev" <daeva...@gmail.com> wrote:
> Form class really doesn't have `strip_tags` method. I think you are
> interested in `strip_tags` functon from `django.utils.html`(and your
> comment says the same). So your method may look like this:
>
>         def clean_title(self):
>                from django.utils.html importstrip_tags
>                title =strip_tags(self.cleaned_data["title"])
>                return title
>
> On Tue, Jan 6, 2009 at 8:14 PM, ChrisL <10000angryc...@googlemail.com> wrote:
>
> > Hi everyone,
>
> > Been bashing against this one for a while now and am keen for
> > suggestions. I'm trying to apply custom validation to forms within
> > Django's default admin. First up, I want to strip out all html from a
> > Title field. Following the official documentation I have developed
> > this:
>
> > ----------------------------
>
> > from django.contrib import admin
> > from django import forms
> > from django.utils.html importstrip_tags
> > from queryclick.qc_news.models import *
>
> > #Custom Data Validation in the Admin Interface
> > class MyArticleAdminForm(forms.ModelForm):
> >        class Meta:
> >                model = Article
>
> >        def clean_title(self):
> >                #Remove all HTML, usingstrip_tags(import from 
> > django.utils.html
> >                title = self.strip_tags('title')
> >                #Always return cleaned data
> >                return self.cleaned_data["title"]
>
> > class ArticleAdmin(admin.ModelAdmin):
> >        list_display = ('title', 'client', 'submitted_date', 'edited_date',
> > 'go_live_date')
> >        list_filter = ('client', 'submitted_date', 'edited_date',
> > 'go_live_date')
> >        ordering = ('-submitted_date',)
> >        search_fields = ('title','client',)
> >        form = MyArticleAdminForm
>
> > admin.site.register(Copywriter)
> > admin.site.register(Client)
> > admin.site.register(Article, ArticleAdmin)
>
> > ----------------------------
>
> > But get an Attribute Error: 'ArticleForm' object has no attribute
> > 'strip_tags' from line 13:
>
> > title = self.strip_tags('title')
>
> > Any and all suggestions warmly welcomed!
--~--~---------~--~----~------------~-------~--~----~
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