天天看点

django admin如何过滤模型字段choices选项

class yourmodeladmin(admin.ModelAdmin):
      def formfield_for_choice_field(self, db_field, request, **kwargs):
        if db_field.name == 'yourfieldname':
            kwargs['choices'] = (
                ('通过', '通过'),
                ('驳回', '驳回'),
            )
        return super(yourmodeladmin, self).formfield_for_choice_field(db_field, request, **kwargs)