如题,在admin.py中重写formfield_for_manytomany函数无法对多对多字段及穿梭框字段生效,以simplepro_demo为例:
@admin.register(ManyToManyTestModel)
class ManyToManyTestModelAdmin(admin.ModelAdmin):
def formfield_for_manytomany(self, db_field, request, **kwargs):
if db_field.name == 'score':
kwargs['queryset'] = ScoreModel.objects.exclude(name='A')
return super().formfield_for_manytomany(db_field, request, **kwargs)
原生管理界面点击增加多对多测试显示效果如下: simplepro显示效果如下: