FurtiveFelon
FurtiveFelon

Reputation: 15166

how to limit the foreignkey dropdown with constraints?

I have a database which keeps track of interaction between two different teams (represented in the admin interface by two different groups). For some fields, i have a foreignkey to Users database, and i would like to limit the dropdown people to only the specific groups.

If anyone have any suggestions, it would be much appreciated!

Upvotes: 14

Views: 14014

Answers (3)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798626

You're looking for limit_choices_to.

Upvotes: 25

Alasdair
Alasdair

Reputation: 308849

To override the choices for a foreign key field in Django admin app, write a formfield_for_foreignkey method.

Upvotes: 3

Bernhard Vallant
Bernhard Vallant

Reputation: 50786

You can change the underlaying queryset for the form field: How do I filter ForeignKey choices in a Django ModelForm?

Upvotes: 3

Related Questions