Inspired by this [terse blog post](http://www.ghastlyfop.com/blog/2008/12/strip-html-tags-from-string-python.html).
This filter was designed to simplify the stripping out of all (x)html in a given template var, while preserving some meta information from anchor, and image tags.
Why is this even useful? If you have pre-assembled portions of templates, or model fields containing html, that you want to use to populate a *search index* like [django-haystack](http://haystacksearch.org/) you can safely discard all the markup, while keeping the text that should be still searchable. Alt text, and title attributes are worth keeping!
- template
- filter
- striptags
This snippet for django-1.2 allows you to use bitwise operators without using QuerySet.extra()
from django.db.models import *
from somewhere import FQ
class BitWise(Model):
type = CharField(max_length=8)
value = IntegerField()
def __unicode__(self):
return '%s - %d' % (self.type, self.value)
>>> BitWise.objects.create(type='django', value=1)
<BitWise: django - 1>
>>> BitWise.objects.create(type='osso', value=3)
<BitWise: osso - 3>
>>> BitWise.objects.create(type='osso', value=7)
<BitWise: osso - 7>
>>> BitWise.objects.filter(FQ(F('value') & 1, 'gt', 0))
[<BitWise: django - 1>, <BitWise: osso - 3>, <BitWise: osso - 7>]
>>> BitWise.objects.filter(FQ(F('value') & 2, 'gt', 0))
[<BitWise: osso - 3>, <BitWise: osso - 7>]
>>> BitWise.objects.filter(FQ(F('value') & 1, 'gt', 0) & Q(type='django'))
[<BitWise: django - 1>]
- filter
- queryset
- bitwise
- operator