admin.py 907 B

1234567891011121314151617181920212223242526272829
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from django.contrib import admin
  4. from .models import ItemType, Item, Loan
  5. admin.site.register(ItemType)
  6. @admin.register(Item)
  7. class ItemAdmin(admin.ModelAdmin):
  8. list_display = ('designation', 'type', 'mac_address', 'user_in_charge',
  9. 'buy_date', 'is_available')
  10. list_filter = ('type__name', 'buy_date')
  11. search_fields = ('designation', 'user_in_charge')
  12. actions = ['give_back']
  13. def give_back(self, request, queryset):
  14. for item in queryset.filter(loans__loan_date_end=None):
  15. item.give_back()
  16. give_back.short_description = 'Rendre le matériel'
  17. @admin.register(Loan)
  18. class LoanAdmin(admin.ModelAdmin):
  19. list_display = ('item', 'user', 'loan_date', 'loan_date_end', 'location')
  20. list_filter = ('item__designation', 'user__username')
  21. search_fields = ('item', 'user')