Django Admin - Filter Choice Field based on current object being edited
<p>I am attempting to exclude the current object being edited from a choice field to select a parent object from the same model. For example:</p>

<pre><code>from django import forms
from django.contrib import admin

class RelationForm(forms.ModelForm):    
    parent = forms.ModelChoiceField(queryset=Ingredient.objects.exclude(id=current_ingredient_id))  

    def save(self, commit=True):
        parent = self.cleaned_data.get('parent', None)
        # ...do something with extra_field here...
        return super(RelationForm, self).save(commit=commit)

    class Meta:
        model = IngredientRelations
        exclude = ['description']

@admin.register(Ingredient)
class IngredientAdmin(admin.ModelAdmin):
    form = RelationForm

    fieldsets = (
        (None, {
             'fields': ('name', 'slug', 'description', 'parent',),
        }),
    ) 
</code></pre>

<p>The difficult comes from getting the current object being edited and then getting its primary key in the RelationForm for the queryset argument.</p>

<p>I have tried using <a href="https://docs.djangoproject.com/en/1.9/ref/contrib/admin/" rel="nofollow">ModelAdmin.formfield_for_foreignkey</a> and <a href="https://docs.djangoproject.com/en/1.9/ref/contrib/admin/" rel="nofollow">ModelAdmin.formfield_for_choice_field</a> in IngredientAdmin with no luck.</p>

<p>Any ideas?</p>