Commit 5323c072 authored by jocelyn's avatar jocelyn

Add loan history and add form to admin item detail view

Allows easier manipulation from

Drops the need of understanding what is an item and what is a loan : everything
can be done from item page.

Fix #189
parent b2c28d2a
......@@ -56,6 +56,39 @@ class AvailabilityFilter(admin.SimpleListFilter):
return queryset
class LoanHistoryInline(admin.TabularInline):
model = Loan
extra = 0
readonly_fields = ('user', 'item', 'loan_date', 'loan_date_end', 'notes')
ordering = ['-loan_date_end']
verbose_name_plural = "Historique de prêt de cet objet"
show_change_link = True
def has_add_permission(self, request, obj=None):
return False
def has_delete_permission(self, request, obj=None):
return False
class AddLoanInline(admin.StackedInline):
model = Loan
extra = 1
max_num = 1
fields = ('user', 'item', 'loan_date', 'notes')
verbose_name_plural = "Déclarer le prêt de cet objet"
classes = ['collapse'] # Django >= 1.10-ready
form = autocomplete_light.modelform_factory(Loan, fields='__all__')
def get_queryset(self, request):
qs = super(AddLoanInline, self).get_queryset(request)
return qs.none()
def has_delete_permission(self, request, obj=None):
return False
class ItemAdmin(admin.ModelAdmin):
list_display = (
......@@ -77,6 +110,8 @@ class ItemAdmin(admin.ModelAdmin):
form = autocomplete_light.modelform_factory(Loan, fields='__all__')
inlines = [AddLoanInline, 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