Django: Limiting choices in a dropdown select field

In an admin form, you can limit the choices in the select dropdown field by setting an option in the model.

Set the option "limit_choices_to" to a filter of some sort.

limit_choices_to = {'pub_date__lte': datetime.now}

Refresh and you will notice that a number of options in your dropdown will be removed.

This also applies to other list type elements.

[ Source ]

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog