Improve admin interface: Transaction list, filters, order list with purchases, buyable list...
This commit is contained in:
parent
7da1e4875b
commit
f7dc5bda50
|
@ -24,12 +24,29 @@ class BuyableAdminForm(forms.ModelForm):
|
|||
|
||||
class BuyableAdmin(admin.ModelAdmin):
|
||||
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(BuyableType)
|
||||
admin.site.register(Purchase)
|
||||
admin.site.register(Order)
|
||||
admin.site.register(BuyableType, BuyableTypeAdmin)
|
||||
#admin.site.register(Purchase) included in Order administration page
|
||||
admin.site.register(Order, OrderAdmin)
|
||||
|
||||
|
|
|
@ -11,6 +11,9 @@ class BuyableType(models.Model):
|
|||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
def itemcount(self):
|
||||
return self.buyable_set.values().count()
|
||||
|
||||
|
||||
class Buyable(models.Model):
|
||||
|
@ -46,7 +49,13 @@ class Buyable(models.Model):
|
|||
item += "/%.2f Pfand" % self.deposit
|
||||
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):
|
||||
""" Represents an order by the user, consists of several :class:`Purchases <Purchase>`. """
|
||||
user = models.ForeignKey(User)
|
||||
|
@ -78,6 +87,12 @@ class Order(models.Model):
|
|||
def __unicode__(self):
|
||||
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):
|
||||
#profile = self.user.get_profile()
|
||||
#if self.id == None:
|
||||
|
|
|
@ -17,8 +17,14 @@ class PluginAdminForm(forms.ModelForm):
|
|||
|
||||
class PluginAdmin(admin.ModelAdmin):
|
||||
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(Plugin, PluginAdmin)
|
||||
admin.site.register(PluginPermission)
|
||||
admin.site.register(PluginPermission, PluginPermissionAdmin)
|
||||
|
||||
|
|
|
@ -372,6 +372,7 @@ textarea {
|
|||
color: black;
|
||||
border: 1px solid #bbb;
|
||||
border-color: #ddd #aaa #aaa #ddd;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
#container .button:active, input[type=submit]:active, input[type=button]:active {
|
||||
|
|
|
@ -3,9 +3,14 @@ from models import Transaction, TransactionType, VirtualTransaction
|
|||
from django.contrib import admin
|
||||
|
||||
class TransactionAdmin(admin.ModelAdmin):
|
||||
list_filter = ('checked','transactionType','amount')
|
||||
list_filter = ('transactionType','checked','user')
|
||||
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):
|
||||
actions = super(TransactionAdmin, self).get_actions(request)
|
||||
del actions['delete_selected']
|
||||
|
@ -17,10 +22,18 @@ class TransactionAdmin(admin.ModelAdmin):
|
|||
for obj in queryset:
|
||||
obj.delete()
|
||||
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)
|
||||
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(TransactionType)
|
||||
admin.site.register(VirtualTransaction)
|
||||
admin.site.register(VirtualTransaction, VirtualTransactionAdmin)
|
||||
|
|
Loading…
Reference in New Issue