I am trying to use a custom filter for a calculated field in admin. I followed the documentation and some other examples and getting this error: Cannot resolve keyword 'kit_frequency' into field. Where did I go wrong?
class KitFrequencyFilter(admin.SimpleListFilter):
title = 'Frequency'
parameter_name = 'kit_frequency'
def lookups(self, request, model_admin):
return (
('Monthly', 'Monthly'),
('Bi-Monthly', 'Bi-Monthly'),
('Quarterly', 'Quarterly'),
)
def queryset(self, request, queryset):
value = self.value()
if value == 'Monthly':
return queryset.filter(kit_frequency='Monthly')
if value == 'Bi-Monthly':
return queryset.filter(kit_frequency='Bi-Monthly')
if value == 'Quarterly':
return queryset.filter(kit_frequency='Quarterly')
return queryset
@admin.register(Contact)
class ContactAdmin(ImportExportModelAdmin):
resource_class = ContactImportResource
list_display = ('full_name','program_code','kit_frequency','author','first_name1', 'last_name1', 'first_name2','last_name2','address1','city','province','postal_code','active_status')
list_filter = ['program_code','author', KitFrequencyFilter]
(simplified) Model:
class Contact(models.Model):
first_name1 = models.CharField(max_length=100, verbose_name='First Name')
last_name1 = models.CharField(max_length=100, verbose_name='Last Name', blank=True)
etc...
def get_kit_frequency(self):
from programs.models import Program
kit_frequency = Program.objects.get(program_code=self.program_code).kit_frequency
return kit_frequency
kit_frequency = property(get_kit_frequency)