class SupplierAdminForm(forms.ModelForm):


    class Meta:
        model = Supplier

def __init__(self, *args, **kwargs):
    super(SupplierAdminForm, self).__init__(*args, **kwargs)
if self.instance:
    self.fields['cat'].queryset = Cat.objects.filter(supplier=self.instance)


class SupplierAdmin(admin.ModelAdmin):
    form = SupplierAdminForm
How do I restrict foreign keys choices to related objects only in django