annotate potd/admin.py @ 943:cf9918328c64

Haystack tweaks for Django 1.7.7. I had to upgrade to Haystack 2.3.1 to get it to work with Django 1.7.7. I also had to update the Xapian backend. But I ran into problems. On my laptop anyway (Ubuntu 14.0.4), xapian gets mad when search terms are greater than 245 chars (or something) when indexing. So I created a custom field that would simply omit terms greater than 64 chars and used this field everywhere I previously used a CharField. Secondly, the custom search form was broken now. Something changed in the Xapian backend and exact searches stopped working. Fortunately the auto_query (which I was using originally and broke during an upgrade) started working again. So I cut the search form back over to doing an auto_query. I kept the form the same (3 fields) because I didn't want to change the form and I think it's better that way.
author Brian Neal <bgneal@gmail.com>
date Wed, 13 May 2015 20:25:07 -0500
parents ee87ea74d46b
children
rev   line source
gremmie@1 1 """
gremmie@1 2 This file contains the admin definitions for the POTD application.
gremmie@1 3 """
bgneal@267 4 from django.contrib import admin
bgneal@267 5 from django.conf import settings
gremmie@1 6
gremmie@1 7 from potd.models import Photo
gremmie@1 8 from potd.models import Current
gremmie@1 9 from potd.models import Sequence
gremmie@1 10
bgneal@267 11
bgneal@330 12 IMG_TAG = '<img src="%s" alt="thumbnail" />'
bgneal@330 13
bgneal@330 14
gremmie@1 15 class PhotoAdmin(admin.ModelAdmin):
bgneal@535 16 fields = ['photo', 'caption', 'description', 'user', 'potd_count']
bgneal@535 17 raw_id_fields = ['user']
bgneal@535 18 list_display = ['__unicode__', 'thumbnail']
bgneal@535 19 actions = ['regen_thumbnail']
bgneal@535 20 search_fields = ['caption', 'description']
gremmie@1 21
bgneal@267 22 class Media:
bgneal@267 23 js = settings.GPP_THIRD_PARTY_JS['tiny_mce']
bgneal@267 24
bgneal@330 25 def thumbnail(self, obj):
bgneal@330 26 return IMG_TAG % obj.thumb.url
bgneal@330 27 thumbnail.allow_tags = True
bgneal@330 28
bgneal@330 29 def regen_thumbnail(self, request, qs):
bgneal@330 30 """
bgneal@330 31 Regenerates the thumbnail for the selected photos.
bgneal@330 32 """
bgneal@330 33 for photo in qs:
bgneal@330 34 photo.generate_thumb()
bgneal@330 35 photo.save()
bgneal@330 36
bgneal@330 37 regen_thumbnail.short_description = "Regenerate thumbs for selected photos"
bgneal@330 38
bgneal@330 39
gremmie@1 40 class CurrentAdmin(admin.ModelAdmin):
bgneal@330 41 list_display = ('__unicode__', 'thumbnail')
gremmie@1 42 raw_id_fields = ('potd', )
gremmie@1 43
bgneal@330 44 def thumbnail(self, obj):
bgneal@330 45 return IMG_TAG % obj.potd.thumb.url
bgneal@330 46 thumbnail.allow_tags = True
bgneal@330 47
bgneal@330 48
gremmie@1 49 admin.site.register(Photo, PhotoAdmin)
gremmie@1 50 admin.site.register(Current, CurrentAdmin)
gremmie@1 51 admin.site.register(Sequence)