view user_photos/admin.py @ 715:820e57e621e8

Use |safe filter on Haystack templates to get better results w/quotes. Content was getting escaped, so text with quotes around it was seemingly missing from the search index. This change fixed that. I verified that the search results will not leak raw HTML to the page so this should be safe to do.
author Brian Neal <bgneal@gmail.com>
date Tue, 17 Sep 2013 20:26:49 -0500
parents d7a0aaabc06c
children cc8de231df5a
line wrap: on
line source
"""Admin definitions for the user_photos application."""
from django.contrib import admin

from user_photos.models import Photo

IMG_TAG = '<img src="%s" alt="thumbnail" />'

class PhotoAdmin(admin.ModelAdmin):
    date_hierarchy = 'upload_date'
    ordering = ['-upload_date']
    raw_id_fields = ['user']
    search_fields = ['user__username', 'user__email']
    list_display = ['__unicode__', 'thumbnail']

    def thumbnail(self, obj):
        return IMG_TAG % obj.thumb_url
    thumbnail.allow_tags = True

admin.site.register(Photo, PhotoAdmin)