Ever wanted a simplified Django tutorial?
Simplifying Django -- has a very clever set up as an example
ColorProperty.objects.filter(dwthemecolor__isnull = False).distinct()This is a filter that turned out to be not quite as useful as I thought because some of the phrases our graphic designer wanted more than one word bolded, but I could totally change around the argument of this filter to take in a number of words to enclose, instead of making the class the optional argument. But, I thought it made a good basic example, so I figured I'd post it. It's useful if you want to visually emphasize the first word of a string, since there's no CSS pseudoselector for that.
( On to the example code! )views.py file, as part of each view where you want to have the variable available: return render_to_response('dir/template.html', {'object': obj, 'link': request.build_absolute_uri()}, RequestContext(request))link variable on the template where you need the URL:def external_link(self):
"""Returns a link for display in the admin table."""
if self.article_link:
return u'Link' % self.article_link
else:
return None
external_link.allow_tags = True
external_link.short_description = "Link"class NewsItemAdmin(admin.ModelAdmin):
list_display = ('title', 'date_published', 'external_link')