Improve admin interface: Transaction list, filters, order list with purchases, buyable list...

This commit is contained in:
Theresa Enghardt 2011-10-30 02:21:56 +01:00
parent 7da1e4875b
commit f7dc5bda50
5 changed files with 62 additions and 10 deletions

View File

@ -24,12 +24,29 @@ class BuyableAdminForm(forms.ModelForm):
class BuyableAdmin(admin.ModelAdmin): class BuyableAdmin(admin.ModelAdmin):
form = BuyableAdminForm form = BuyableAdminForm
list_display = ('name','price','deposit','types')
list_filter = ['buyableType']
search_fields = ['name','description']
class BuyableTypeAdmin(admin.ModelAdmin):
list_display = ('name','itemcount')
class PurchaseInline(admin.TabularInline):
model = Purchase
fields = ('buyable','isDeposit','price')
class OrderAdmin(admin.ModelAdmin):
list_display = ('user','price','dateTime','itemList')
list_filter = ['user']
search_fields = ['user__username','user__first_name','user__last_name']
date_hierarchy = 'dateTime'
ordering = ['-dateTime']
inlines = [PurchaseInline,]
admin.site.register(Buyable, BuyableAdmin) admin.site.register(Buyable, BuyableAdmin)
admin.site.register(BuyableType) admin.site.register(BuyableType, BuyableTypeAdmin)
admin.site.register(Purchase) #admin.site.register(Purchase) included in Order administration page
admin.site.register(Order) admin.site.register(Order, OrderAdmin)

View File

@ -11,6 +11,9 @@ class BuyableType(models.Model):
def __unicode__(self): def __unicode__(self):
return self.name return self.name
def itemcount(self):
return self.buyable_set.values().count()
class Buyable(models.Model): class Buyable(models.Model):
@ -46,7 +49,13 @@ class Buyable(models.Model):
item += "/%.2f Pfand" % self.deposit item += "/%.2f Pfand" % self.deposit
item += ")" item += ")"
return item return item
def types(self):
typelist = ""
for item in self.buyableType.values_list():
typelist += item[1] + ", "
return typelist.rstrip(u", ")
class Order(models.Model): class Order(models.Model):
""" Represents an order by the user, consists of several :class:`Purchases <Purchase>`. """ """ Represents an order by the user, consists of several :class:`Purchases <Purchase>`. """
user = models.ForeignKey(User) user = models.ForeignKey(User)
@ -78,6 +87,12 @@ class Order(models.Model):
def __unicode__(self): def __unicode__(self):
return "Price %s, User %s" % (self.price, self.user) return "Price %s, User %s" % (self.price, self.user)
def itemList(self):
l = ""
for item in self.purchase_set.all():
l += item.buyable.name + u", "
return l.rstrip(u", ")
#def save(self, *args, **kwargs): #def save(self, *args, **kwargs):
#profile = self.user.get_profile() #profile = self.user.get_profile()
#if self.id == None: #if self.id == None:

View File

@ -17,8 +17,14 @@ class PluginAdminForm(forms.ModelForm):
class PluginAdmin(admin.ModelAdmin): class PluginAdmin(admin.ModelAdmin):
form = PluginAdminForm form = PluginAdminForm
list_display = ('name','version','author','descr')
list_filter = ['author',]
class PluginPermissionAdmin(admin.ModelAdmin):
list_display = ('user','plugin')
list_filter = ('user','plugin')
admin.site.register(UserProfile) admin.site.register(UserProfile)
admin.site.register(Plugin, PluginAdmin) admin.site.register(Plugin, PluginAdmin)
admin.site.register(PluginPermission) admin.site.register(PluginPermission, PluginPermissionAdmin)

View File

@ -372,6 +372,7 @@ textarea {
color: black; color: black;
border: 1px solid #bbb; border: 1px solid #bbb;
border-color: #ddd #aaa #aaa #ddd; border-color: #ddd #aaa #aaa #ddd;
margin: 0px;
} }
#container .button:active, input[type=submit]:active, input[type=button]:active { #container .button:active, input[type=submit]:active, input[type=button]:active {

View File

@ -3,9 +3,14 @@ from models import Transaction, TransactionType, VirtualTransaction
from django.contrib import admin from django.contrib import admin
class TransactionAdmin(admin.ModelAdmin): class TransactionAdmin(admin.ModelAdmin):
list_filter = ('checked','transactionType','amount') list_filter = ('transactionType','checked','user')
actions = ['really_delete_selected'] actions = ['really_delete_selected']
list_display = ('user', 'transactionType', 'amount', 'dateTime', 'checked')
list_display_links = ('user', 'transactionType')
search_fields = ['user__username','user__first_name','user__last_name']
date_hierarchy = 'dateTime'
ordering = ['-dateTime']
def get_actions(self, request): def get_actions(self, request):
actions = super(TransactionAdmin, self).get_actions(request) actions = super(TransactionAdmin, self).get_actions(request)
del actions['delete_selected'] del actions['delete_selected']
@ -17,10 +22,18 @@ class TransactionAdmin(admin.ModelAdmin):
for obj in queryset: for obj in queryset:
obj.delete() obj.delete()
num = queryset.count() num = queryset.count()
message = "%s transaction%s" % (num, (num != 1 and "s" or "")) message = "%s Transaktion%s" % (num, (num != 1 and "en" or ""))
self.message_user(request, u"Erfolgreich %s gelöscht." % message) self.message_user(request, u"Erfolgreich %s gelöscht." % message)
really_delete_selected.short_description = u"Ausgewählte transactions löschen" really_delete_selected.short_description = u"Ausgewählte Transaktion(en) löschen"
class VirtualTransactionAdmin(admin.ModelAdmin):
list_display = ('user','recipient','amount','dateTime','comment')
list_display_links = ('user','recipient')
list_filter = ('user','recipient')
search_fields = ['user__username','recipient__username','comment']
date_hierarchy = 'dateTime'
ordering = ['-dateTime']
admin.site.register(Transaction, TransactionAdmin) admin.site.register(Transaction, TransactionAdmin)
admin.site.register(TransactionType) admin.site.register(TransactionType)
admin.site.register(VirtualTransaction) admin.site.register(VirtualTransaction, VirtualTransactionAdmin)