+
+# Backport from Django 3.1.
+class EmptyFieldListFilter(FieldListFilter):
+ with_empty_str = False
+
+ def __init__(self, field, request, params, model, model_admin, field_path):
+ self.lookup_kwarg = '%s__isempty' % field_path
+ self.lookup_val = params.get(self.lookup_kwarg)
+ super().__init__(field, request, params, model, model_admin, field_path)
+
+ def queryset(self, request, queryset):
+ if self.lookup_kwarg not in self.used_parameters:
+ return queryset
+ if self.lookup_val not in ('0', '1'):
+ raise IncorrectLookupParameters
+
+ lookup_condition = Q(**{'%s__isnull' % self.field_path: True})
+ if self.with_empty_str:
+ lookup_condition |= Q(**{self.field_path: ''})
+ if self.lookup_val == '1':
+ return queryset.filter(lookup_condition)
+ return queryset.exclude(lookup_condition)
+
+ def expected_parameters(self):
+ return [self.lookup_kwarg]
+
+ def choices(self, changelist):
+ for lookup, title in (
+ (None, _('All')),
+ ('1', _('Empty')),
+ ('0', _('Not empty')),
+ ):
+ yield {
+ 'selected': self.lookup_val == lookup,
+ 'query_string': changelist.get_query_string({self.lookup_kwarg: lookup}),
+ 'display': title,
+ }
+
+
+class PayedListFilter(SimpleListFilter):
+ title = 'pobrane'
+ parameter_name = 'payed'
+ def lookups(self, request, model_admin):
+ return (
+ ('yes', 'tak'),
+ ('no', 'nie'),
+ )
+
+ def queryset(self, request, queryset):
+ if self.value() == 'yes':
+ return queryset.filter(payment__is_dd=True, payment__realised=True).distinct()
+ if self.value() == 'no':
+ return queryset.exclude(payment__is_dd=True, payment__realised=True).distinct()
+
+
+
+class BankExportFeedbackLineInline(admin.TabularInline):
+ model = models.BankExportFeedbackLine
+ extra = 0
+
+class BankPaymentInline(admin.TabularInline):
+ model = models.Payment
+ extra = 0
+