1234567891011121314151617181920212223242526272829 |
- # -*- coding: utf-8 -*-
- from __future__ import unicode_literals
- from django.contrib import admin
- from .models import ItemType, Item, Loan
- admin.site.register(ItemType)
- @admin.register(Item)
- class ItemAdmin(admin.ModelAdmin):
- list_display = ('designation', 'type', 'mac_address', 'user_in_charge',
- 'buy_date', 'is_available')
- list_filter = ('type__name', 'buy_date')
- search_fields = ('designation', 'user_in_charge')
- actions = ['give_back']
- def give_back(self, request, queryset):
- for item in queryset.filter(loans__loan_date_end=None):
- item.give_back()
- give_back.short_description = 'Rendre le matériel'
- @admin.register(Loan)
- class LoanAdmin(admin.ModelAdmin):
- list_display = ('item', 'user', 'loan_date', 'loan_date_end', 'location')
- list_filter = ('item__designation', 'user__username')
- search_fields = ('item', 'user')
|