| | 930 | .. method:: ModelAdmin.formfield_for_choice_field(self, db_field, request, **kwargs) |
| | 931 | |
| | 932 | Similarly as the ``formfield_for_foreignkey`` and ``formfield_for_manytomany`` |
| | 933 | methods, the ``formfield_for_choice_field`` method can be overridden to |
| | 934 | change the default formfield for a field that has declared choices. For example, |
| | 935 | if the choices available to a superuser should be different than those |
| | 936 | available to regular staff, you could proceed as follows:: |
| | 937 | |
| | 938 | class MyModelAdmin(admin.ModelAdmin): |
| | 939 | def formfield_for_choice_field(self, db_field, request, **kwargs): |
| | 940 | if db_field.name == "status": |
| | 941 | kwargs['choices'] = ( |
| | 942 | ('accepted', 'Accepted'), |
| | 943 | ('denied', 'Denied'), |
| | 944 | ) |
| | 945 | if request.user.is_superuser: |
| | 946 | kwargs['choices'] += (('ready', 'Ready for deployment'),) |
| | 947 | return super(MyModelAdmin, self).formfield_for_choice_field(db_field, request, **kwargs) |
| | 948 | |