limit choices to - Django limit_choices_to for multiple fields with "or" condition -


i trying limit choices field, checking values of 2 columns, 'share_holder' , 'distributor'. if of them true, want choice.

with below version, got choices satisfying both conditions ('share_holder': true , 'distributor': true).

limit_choices_to={'share_holder': true, 'distributor': true} 

however, need choices ('share_holder': true or 'distributor': true).

you can use q objects achieve this.

from django.db.models import q   limit_choices_to=q(share_holder=true) | q(distributor=true) 

official docs on foreignkey.limit_choices_to


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -