2👍
✅
I’m not sure if you can do this right on the model, but if you could it would be done with F
. Something like:
from django.db.models import Q, F
...
limit_choices_to=Q(userprofile__status='teacher') & ~Q(id=F('owner_id'))
You have to use Q
because you can’t assert a negative with the dictionary pattern. The ~
negates the second Q
and F('owner_id')
is use to select the value for owner.
Like I said, though, I haven’t tried to do this myself, so I can’t say if it will work or not. You’ll just have to give it a whirl and let us know.
Source:stackexchange.com