views:

32

answers:

2

I have these models:

class Client(models.Model):
    is_provider = models.BooleanField()

class Billing(models.Model):
    client = models.ForeignKey(Client)

I want to limit the choices of ForeignKey to show only the clients with is_provider=True. Is there something like:

limit_choices_to = {'is_provider': True}

Or anything I can use to filter the ForeignKey?

+1  A: 

Do you have tried the following:

limit_choices_to = {'client__is_provider': True}
muksie
If only I could set two answers.. Anyway, thanks for the answer :)
Oscar Carballal
+1  A: 

Yes, you have the exact syntax already.

client = models.ForeignKey(Client, limit_choices_to = {'is_provider': True})
Daniel Roseman
Thanks! Didn't realize it was so easy
Oscar Carballal