+class ChildrenFilter(admin.SimpleListFilter):
+ title = 'Status utworu podrzędnego'
+ parameter_name = 'book_children'
+
+ def lookups(self, requesrt, model_admin):
+ return [
+ ('no', 'bez podrzędnych'),
+ ('only', 'tylko podrzędne'),
+ ]
+
+ def queryset(self, request, queryset):
+ v = self.value()
+ if v == 'no':
+ return queryset.filter(parent=None)
+ elif v == 'only':
+ return queryset.exclude(parent=None)
+ else:
+ return queryset
+
+