The question: In the model Project how do i show only provinces from Province model, that has country set to X (If i have countries "USA" and "Canada" i want the field province to show list of provinces in "USA" only/preselecting country).
You would filter the choices available to the field in your form with a query like this:
Province.objects.filter(country__name="X") # where X is the country you want.
I'm not familiar with smart-selects, so you would need to look at their documentation to figure out where that filter goes, but it is probably part of the 'choices' keyword argument for your form field.
If you plan to do this though, you may want to add unique=True to the name field on Country (unless you plan on having multiple countries with the same name, of course). I believe this also adds an index, which will help speed up your searches. If you can't do unique=True, at least set db_index=True.
-James
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciX3D%2B6YmvtCcZ-HOZ_4HFvNUturh5%3DQSxCmJ2oS-AYnjg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment