Developer 2024 🎇限时优惠进行中,现在购买立即享受

现在购买

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

avatarEthan
5月9日734次阅读

如题,在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个评论