annotate shoutbox/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 automatic admin site definitions for the shoutbox models.
gremmie@1 3 """
gremmie@1 4 from django.contrib import admin
gremmie@1 5 from shoutbox.models import Shout
bgneal@13 6 from shoutbox.models import ShoutFlag
gremmie@1 7
gremmie@1 8 class ShoutAdmin(admin.ModelAdmin):
bgneal@151 9 list_display = ('__unicode__', 'user', 'shout_date')
bgneal@13 10 raw_id_fields = ('user', )
bgneal@151 11 date_hierarchy = 'shout_date'
bgneal@151 12 exclude = ('html', )
bgneal@151 13 search_fields = ('shout', 'user__username')
bgneal@151 14 list_filter = ('shout_date', )
bgneal@151 15
bgneal@13 16
bgneal@13 17 class ShoutFlagAdmin(admin.ModelAdmin):
bgneal@151 18 list_display = ('__unicode__', 'flag_date', 'shout', 'get_shout_url')
bgneal@151 19 actions = ('delete_shouts', )
bgneal@151 20
bgneal@151 21 def delete_shouts(self, request, qs):
bgneal@151 22 """
bgneal@151 23 Admin action function to delete the shouts associated with the shout
bgneal@151 24 flags.
bgneal@151 25 """
bgneal@151 26 for flag in qs:
bgneal@151 27 flag.shout.delete() # will delete the flag too
bgneal@151 28
bgneal@151 29 delete_shouts.short_description = "Delete selected flags & shouts"
bgneal@13 30
gremmie@1 31
gremmie@1 32 admin.site.register(Shout, ShoutAdmin)
bgneal@13 33 admin.site.register(ShoutFlag, ShoutFlagAdmin)
bgneal@13 34