[Fixed]-Filtering between related objects in admin panel

1👍

Yep, but you’ll have to override the admin form for that and filter the choices in the __init__() method of the form. The form __init__() should look sth like this (warning – untested code):

def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)
    self.fields['user_transactions'].choices = transaction.objects.filter(user_id=user_id)

For information about how to override admin form, check out the docs: https://docs.djangoproject.com/en/1.9/ref/contrib/admin/#django.contrib.admin.ModelAdmin.form

Leave a comment