|
|
|
@ -9,7 +9,7 @@ from easy_select2 import apply_select2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Register your models here.
|
|
|
|
# Register your models here.
|
|
|
|
class OwnershipInline(admin.StackedInline):
|
|
|
|
class OwnershipInline(admin.TabularInline):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
This shows the ownership selection directly in the MaterialPart edit
|
|
|
|
This shows the ownership selection directly in the MaterialPart edit
|
|
|
|
view
|
|
|
|
view
|
|
|
|
@ -22,29 +22,33 @@ class OwnershipInline(admin.StackedInline):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NotTooOldFilter(SimpleListFilter):
|
|
|
|
class NotTooOldFilter(SimpleListFilter):
|
|
|
|
title = _('Age')
|
|
|
|
title = _('Age')
|
|
|
|
parameter_name = 'age'
|
|
|
|
parameter_name = 'age'
|
|
|
|
|
|
|
|
|
|
|
|
def lookups(self, request, model_admin):
|
|
|
|
def lookups(self, request, model_admin):
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
('too_old', _('Not too old')),
|
|
|
|
('too_old', _('Not too old')),
|
|
|
|
('not_too_old', _('Too old')),
|
|
|
|
('not_too_old', _('Too old')),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def queryset(self, request, queryset):
|
|
|
|
|
|
|
|
if self.value() == 'too_old':
|
|
|
|
|
|
|
|
return queryset.filter(pk__in=[x.pk for x in queryset.all() if x.not_too_old()])
|
|
|
|
|
|
|
|
if self.value() == 'not_too_old':
|
|
|
|
|
|
|
|
return queryset.filter(pk__in=[x.pk for x in queryset.all() if not x.not_too_old()])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def queryset(self, request, queryset):
|
|
|
|
|
|
|
|
if self.value() == 'too_old':
|
|
|
|
|
|
|
|
return queryset.filter(pk__in=[x.pk for x in queryset.all() if x.not_too_old()])
|
|
|
|
|
|
|
|
if self.value() == 'not_too_old':
|
|
|
|
|
|
|
|
return queryset.filter(pk__in=[x.pk for x in queryset.all() if not x.not_too_old()])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MaterialAdmin(admin.ModelAdmin):
|
|
|
|
class MaterialAdmin(admin.ModelAdmin):
|
|
|
|
"""Edit view of a MaterialPart"""
|
|
|
|
"""Edit view of a MaterialPart"""
|
|
|
|
|
|
|
|
|
|
|
|
list_display = ('name', 'description', 'quantity_real', 'buy_date', 'lifetime', 'not_too_old', 'photo')
|
|
|
|
list_display = ('name', 'description', 'quantity_real',
|
|
|
|
|
|
|
|
'ownership_overview', 'buy_date',
|
|
|
|
|
|
|
|
'lifetime', 'not_too_old', 'admin_thumbnail')
|
|
|
|
inlines = [OwnershipInline]
|
|
|
|
inlines = [OwnershipInline]
|
|
|
|
list_filter = (NotTooOldFilter,)
|
|
|
|
list_filter = (NotTooOldFilter,)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Media:
|
|
|
|
|
|
|
|
css = {'all': ('admin/css/tabular_hide_original.css',)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
admin.site.register(MaterialPart, MaterialAdmin)
|
|
|
|
admin.site.register(MaterialPart, MaterialAdmin)
|
|
|
|
|