尝试让django-polymorphic在admin中工作。我有许多继承自BaseModel的ChildModel,但点击Django管理员中的任何一个都会导致所有BaseModel对象的列表,这对我来说是无用的。我已经尝试重新定义查询集并包含list_filter作为文档(过时,我已经了解到)建议,但似乎都没有任何效果。
class BaseModelChildAdmin(PolymorphicChildModelAdmin):
base_model = BaseModel
show_in_index = False
form = BaseModelForm
class ChildModelAdmin(BaseModelChildAdmin):
exclude = ('asset_url', 'asset_file')
base_model = ChildModel
show_in_index = True
def queryset(self, request):
qs = ChildModel.objects.all()
return qs
class BaseModelAdmin(PolymorphicParentModelAdmin):
base_model = BaseModel
child_models = [(ChildModel, ChildModelAdmin)]
list_filter = (PolymorphicChildModelFilter,)