diff shoutbox/admin.py @ 581:ee87ea74d46b

For Django 1.4, rearranged project structure for new manage.py.
author Brian Neal <bgneal@gmail.com>
date Sat, 05 May 2012 17:10:48 -0500
parents gpp/shoutbox/admin.py@e1d1a70d312d
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/shoutbox/admin.py	Sat May 05 17:10:48 2012 -0500
@@ -0,0 +1,34 @@
+"""
+This file contains the automatic admin site definitions for the shoutbox models.
+"""
+from django.contrib import admin
+from shoutbox.models import Shout
+from shoutbox.models import ShoutFlag
+
+class ShoutAdmin(admin.ModelAdmin):
+    list_display = ('__unicode__', 'user', 'shout_date')
+    raw_id_fields = ('user', )
+    date_hierarchy = 'shout_date'
+    exclude = ('html', )
+    search_fields = ('shout', 'user__username')
+    list_filter = ('shout_date', )
+
+
+class ShoutFlagAdmin(admin.ModelAdmin):
+    list_display = ('__unicode__', 'flag_date', 'shout', 'get_shout_url')
+    actions = ('delete_shouts', )
+
+    def delete_shouts(self, request, qs):
+        """
+        Admin action function to delete the shouts associated with the shout
+        flags.
+        """
+        for flag in qs:
+            flag.shout.delete()     # will delete the flag too
+
+    delete_shouts.short_description = "Delete selected flags & shouts"
+
+
+admin.site.register(Shout, ShoutAdmin)
+admin.site.register(ShoutFlag, ShoutFlagAdmin)
+