Browse Source

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

master
Theresa Enghardt 11 years ago
parent
commit
f7dc5bda50
  1. 23
      k4ever/buyable/admin.py
  2. 17
      k4ever/buyable/models.py
  3. 8
      k4ever/main/admin.py
  4. 1
      k4ever/media/css/admin.css
  5. 23
      k4ever/transaction/admin.py

23
k4ever/buyable/admin.py

@ -24,12 +24,29 @@ class BuyableAdminForm(forms.ModelForm): @@ -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)

17
k4ever/buyable/models.py

@ -11,6 +11,9 @@ class BuyableType(models.Model): @@ -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): @@ -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): @@ -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:

8
k4ever/main/admin.py

@ -17,8 +17,14 @@ class PluginAdminForm(forms.ModelForm): @@ -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)

1
k4ever/media/css/admin.css

@ -372,6 +372,7 @@ textarea { @@ -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 {

23
k4ever/transaction/admin.py

@ -3,9 +3,14 @@ from models import Transaction, TransactionType, VirtualTransaction @@ -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): @@ -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…
Cancel
Save