Models
class A(SiteAwareModel):
name = models.CharField(max_length = 255, blank = False)
description = models.TextField(blank = True, null = True)
class Meta:
def key_count(self):
return B.objects.count(self)
Admin
class AAdmin(admin.ModelAdmin):
list_display = ('key_count')
list_filter = ('key_count')
admin.site.register(A, AAdmin)
Problem
I have a model A which has its own fields (name, description). Further, model A calculates a key count by using model B (no foreign key relation).
I want to access the key_count in the admin panel. I can see a column in the admin meaning list_display works but when I try using it in list_filter it throws an error.
'AAdmin.list_filter1' refers to 'key_count' which does not refer to a Field.
End result
I want to make a filter which would show key_count > 10
What I have done(without success)
I have already tried doing it via managers with the help of THIS blog post
What I DO NOT want
I do not want to change my model by writing new migrations.