[Answered ]-Django, showing only matches condition in lookup

2👍

you need to custom the admin part in you app.

class VehicleAdmin(admin.ModelAdmin):                                                                                               
    def formfield_for_foreignkey(self, db_field, request, **kwargs):                                                                
        if db_field.name == "driver":                                                                                               
            kwargs["queryset"] = Crew.objects.filter(isActive=True)                                                                 
        return super(VehicleAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)                                      


admin.site.register(Vehicle, VehicleAdmin) 

https://docs.djangoproject.com/en/1.11/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey

Leave a comment