Commit 34c04868 authored by jocelyn's avatar jocelyn

Separate loan history from current loan in Item admin detail view

Clearer, follows the same logic as maillists
parent 863a0595
......@@ -56,6 +56,25 @@ class AvailabilityFilter(admin.SimpleListFilter):
return queryset
class CurrentLoanInline(admin.TabularInline):
model = Loan
extra = 0
fields = ('user', 'item', 'short_date', 'notes')
readonly_fields = ('user', 'item', 'short_date', 'notes')
verbose_name_plural = "Emprunt en cours"
show_change_link = True
def get_queryset(self, request):
qs = super(CurrentLoanInline, self).get_queryset(request)
return qs.running()
def has_add_permission(self, request, obj=None):
return False
def has_delete_permission(self, request, obj=None):
return False
class LoanHistoryInline(admin.TabularInline):
model = Loan
extra = 0
......@@ -64,6 +83,11 @@ class LoanHistoryInline(admin.TabularInline):
ordering = ['-loan_date_end']
verbose_name_plural = "Historique de prêt de cet objet"
show_change_link = True
classes = ['collapse'] # Django >= 1.10-ready
def get_queryset(self, request):
qs = super(LoanHistoryInline, self).get_queryset(request)
return qs.finished()
def has_add_permission(self, request, obj=None):
return False
......@@ -111,7 +135,7 @@ class ItemAdmin(admin.ModelAdmin):
form = autocomplete_light.modelform_factory(Loan, fields='__all__')
inlines = [AddLoanInline, LoanHistoryInline]
inlines = [AddLoanInline, CurrentLoanInline, LoanHistoryInline]
def give_back(self, request, queryset):
for item in queryset.filter(loans__loan_date_end=None):
......
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