I've been playing around with a reusable/declarative syntax for doing this, 
as I seem to do it all of the time.

https://bitbucket.org/schinckel/django-filtered-form

You inherit from FilteredForm, and set either simple 'filters' or 
'instance_filters' attributes on the form class:

    class MyModelForm(FilteredForm):
        filters = {'staff': models.Q(deleted=False)}
        instance_filters = {'staff': 'company.people'}

'filters' allows you to use Q objects to filter the related objects (in 
this case, only selecting non-deleted staff), and instance_filters allows 
you to set the queryset based on an attribute that the instance has. In the 
case above, it would set the queryset for staff to the MyModel's 
company.people attribute chain, and then filter those objects based on the 
deleted attribute.

Until about 5 minutes ago it was a private repo on bitbucket: I'm using it 
on a project (in production), but it needs cleaning up, documenting and 
packaging.

Matt.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/q3KkDec7XUQJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to