No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

admin.py 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # This file is part of k4ever, a point-of-sale system
  2. # Contact............ <k4ever@lists.someserver.de>
  3. # Website............ http://k4ever.someserver.de/
  4. # Bug tracker........ http://k4ever.someserver.de/report
  5. #
  6. # Licensed under GNU Affero General Public License v3 or later
  7. from models import Buyable, BuyableType, Purchase, Order
  8. from django.contrib import admin
  9. from django import forms
  10. from PIL import Image
  11. from django.core.files.uploadedfile import InMemoryUploadedFile
  12. class BuyableAdminForm(forms.ModelForm):
  13. """ Special BuyableAdminForm which checks the buyable image for an 1:1 aspect ratio. """
  14. class Meta:
  15. model = Buyable
  16. def clean_image(self):
  17. img = self.cleaned_data['image']
  18. width, height = (0, 0)
  19. if isinstance(img, InMemoryUploadedFile):
  20. i = Image.open(img)
  21. width, height = i.size
  22. else:
  23. width, height = img.width, img.height
  24. if width != height:
  25. raise forms.ValidationError("Aspect ratio of image should be 1:1 (width x height was (%dx%d))"% (width, height))
  26. return self.cleaned_data['image']
  27. class BuyableAdmin(admin.ModelAdmin):
  28. form = BuyableAdminForm
  29. list_display = ('name','price','deposit','types')
  30. list_filter = ['buyableType']
  31. search_fields = ['name','description']
  32. class BuyableTypeAdmin(admin.ModelAdmin):
  33. list_display = ('name','itemcount')
  34. class PurchaseInline(admin.TabularInline):
  35. model = Purchase
  36. fields = ('buyable','isDeposit','price')
  37. class OrderAdmin(admin.ModelAdmin):
  38. list_display = ('user','price','dateTime','itemList')
  39. list_filter = ['user']
  40. search_fields = ['user__username','user__first_name','user__last_name']
  41. date_hierarchy = 'dateTime'
  42. ordering = ['-dateTime']
  43. inlines = [PurchaseInline,]
  44. admin.site.register(Buyable, BuyableAdmin)
  45. admin.site.register(BuyableType, BuyableTypeAdmin)
  46. #admin.site.register(Purchase) included in Order administration page
  47. admin.site.register(Order, OrderAdmin)