You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
from django.contrib import admin
|
|
from django.utils.translation import ugettext_lazy as _
|
|
from django.contrib.admin import SimpleListFilter
|
|
|
|
from .models import MaterialPart, Ownership
|
|
|
|
|
|
# Register your models here.
|
|
class OwnershipInline(admin.StackedInline):
|
|
"""
|
|
This shows the ownership selection directly in the MaterialPart edit
|
|
view
|
|
"""
|
|
model = Ownership
|
|
extra = 0
|
|
|
|
|
|
class NotTooOldFilter(SimpleListFilter):
|
|
title = _('Age')
|
|
parameter_name = 'age'
|
|
|
|
def lookups(self, request, model_admin):
|
|
return (
|
|
('too_old', _('Not 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()])
|
|
|
|
|
|
|
|
class MaterialAdmin(admin.ModelAdmin):
|
|
"""Edit view of a MaterialPart"""
|
|
|
|
list_display = ('name', 'quantity_real', 'buy_date', 'lifetime', 'not_too_old', 'photo')
|
|
inlines = [OwnershipInline]
|
|
list_filter = (NotTooOldFilter,)
|
|
|
|
|
|
admin.site.register(MaterialPart, MaterialAdmin)
|