Commit b6638572 authored by jocelyn's avatar jocelyn

Remove the loan admin views

Everything is handled from Item as of now
parent c947623a
......@@ -5,7 +5,6 @@ from __future__ import unicode_literals
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.forms import ModelChoiceField
import autocomplete_light
from .models import ItemType, Item, Loan, Storage
......@@ -202,54 +201,6 @@ class StatusFilter(admin.SimpleListFilter):
return queryset
class BorrowerFilter(admin.SimpleListFilter):
title = 'Adhérent emprunteur'
parameter_name = 'user'
def lookups(self, request, model_admin):
users = set()
for loan in model_admin.get_queryset(request):
users.add((, loan.user))
return users
def queryset(self, request, queryset):
if self.value():
return queryset.filter(user=self.value())
return queryset
class ItemChoiceField(ModelChoiceField):
# On surcharge cette méthode pour afficher mac et n° de série dans le menu
# déroulant de sélection d'un objet dans la création d'un prêt.
def label_from_instance(self, obj):
return obj.designation + ' ' + obj.get_mac_and_serial()
class LoanAdmin(admin.ModelAdmin):
list_display = ('item', 'get_mac_and_serial', 'user', 'loan_date', 'loan_date_end')
list_filter = (StatusFilter, BorrowerFilter, 'item__designation')
search_fields = (
'user__nickname', 'user__username',
'user__first_name', 'user__last_name', )
actions = ['end_loan']
def end_loan(self, request, queryset):
end_loan.short_description = 'Mettre fin au prêt'
form = autocomplete_light.modelform_factory(Loan, fields='__all__')
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if == 'item':
kwargs['queryset'] = Item.objects.all()
return ItemChoiceField(**kwargs)
return super(LoanAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
class StorageAdmin(admin.ModelAdmin):
list_display = ('name', 'truncated_notes', 'items_count')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment