tags:

views:

61

answers:

1

Django has great fields under the local flavors package for specific local form fields like state and postal code. However, I need to merge two or more of them together(e.g. merge Canadian provinces and American states into one field, or have Canadian and American postal/zip codes validate on the same field) or some how instantiate form object fields based on what country a user selects. Does anyone have any experience with this same problem? What solution did you use?

A: 

Are you looking for a drop down list, for instance:

<h3>Select Country:</h3>
<select>
    <option>America</option>
    <option>Canada</option>
</select>

<h3>Select Province/State:</h3>
<select>
</select>

The province/state list will then be automatically populated with states if America is selected or provinces if Canada is selected. You could have a Country table:

Country
-------
America
Canada

A province/state table:

ProvSate
-------
(California, foreign key to Country)
(Ontario, foreign key to Country)

The above is a rough idea on how to solve that kind of problem. There's not much validation in the above since choosing the appropriate countries will generate the corresponding prov/states. If the country has no state or prov, return an empty drop down list for prov/state.

Thierry Lam