There is unfortunately no easy way to do this purely server-side. However, it should be relatively easy to accomplish with some JavaScript – toggling the visibility of the reason field based on the status. The following is an example using jQuery:
$(document).ready(function() {
// Toggle visibility on page load
setReasonVisibility();
// Toggle visibility on status change
$('form #id_status').bind('change', setReasonVisibility)
function setReasonVisibility() {
var form = $('form');
var status = $(form).find('#id_status').val();
if (status == 'rejected')
$(form).find('#id_reason').show();
else
$(form).find('#id_reason').hide();
}
});
To have the form load the JavaScript file, you need to refer to it in a Media
class to the form for your model, somehow like this:
class YourModelForm(forms.ModelForm):
class Meta:
model = YourModel
class Media:
js = ('path/to/jquery.js', 'path/to/your-js-file.js')
This solution should work seamlessly within the Django admin.