filtered ModelChoiceField queries
ModelChoiceField allows you to use filtered queries to simplify your forms. This is great for adding objects but can fall down when you edit an existing object and the original query no longer contains the referenced field (e.g. I like to use an "active" field in several objects). The fix is simply to include an extra param: Q(pk=object_id). You have to do this in the __init__ method to get the object_id. A nice thing about this is that it works for ModelForms as well as custom Forms.
- newforms
- modelchoicefield
- modelform