|
@@ -31,12 +31,33 @@ class OwnerFilter(admin.SimpleListFilter):
|
|
return queryset
|
|
return queryset
|
|
|
|
|
|
|
|
|
|
|
|
+class AvailabilityFilter(admin.SimpleListFilter):
|
|
|
|
+ title = "Disponibilité"
|
|
|
|
+ parameter_name = 'availability'
|
|
|
|
+
|
|
|
|
+ def lookups(self, request, model_admin):
|
|
|
|
+ return [
|
|
|
|
+ ('available', 'Disponible'),
|
|
|
|
+ ('borrowed', 'Emprunté'),
|
|
|
|
+ ]
|
|
|
|
+
|
|
|
|
+ def queryset(self, request, queryset):
|
|
|
|
+ if self.value() == 'available':
|
|
|
|
+ return queryset.available()
|
|
|
|
+ elif self.value() == 'borrowed':
|
|
|
|
+ return queryset.borrowed()
|
|
|
|
+ else:
|
|
|
|
+ return queryset
|
|
|
|
+
|
|
|
|
+
|
|
@admin.register(Item)
|
|
@admin.register(Item)
|
|
class ItemAdmin(admin.ModelAdmin):
|
|
class ItemAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
list_display = (
|
|
'designation', 'type', 'mac_address', 'serial', 'owner',
|
|
'designation', 'type', 'mac_address', 'serial', 'owner',
|
|
'buy_date', 'is_available')
|
|
'buy_date', 'is_available')
|
|
- list_filter = ('type__name', 'storage', 'buy_date', OwnerFilter)
|
|
|
|
|
|
+ list_filter = (
|
|
|
|
+ AvailabilityFilter, 'type__name', 'storage',
|
|
|
|
+ 'buy_date', OwnerFilter)
|
|
search_fields = (
|
|
search_fields = (
|
|
'designation', 'mac_address', 'serial',
|
|
'designation', 'mac_address', 'serial',
|
|
'owner__email', 'owner__nickname',
|
|
'owner__email', 'owner__nickname',
|