I have a model that has a field named \"state\":
class Foo(models.Model):
...
state = models.IntegerField(choices = STATES)
...
You need to use a custom ModelForm in the ModelAdmin class for that model. In the custom ModelForm's __init__ method, you can dynamically set the choices for that field:
class FooForm(forms.ModelForm):
class Meta:
model = Foo
def __init__(self, *args, **kwargs):
super(FooForm, self).__init__(*args, **kwargs)
current_state = self.instance.state
...construct available_choices based on current state...
self.fields['state'].choices = available_choices
You'd use it like this:
class FooAdmin(admin.ModelAdmin):
form = FooForm