首页
Simplepro多对多字段重写formfield_for_manytomany无法生效

Simplepro多对多字段重写formfield_for_manytomany无法生效

05-09 20:07:08
68
1

如题,在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)

原生管理界面点击增加多对多测试显示效果如下: image.png simplepro显示效果如下: image.png

评论(1)