What’s the common practice to represent postal addresses in Django models? Is there a library for custom model fields that include postal address fields and potentially handle validation and formatting?
If no library exists, how can I write one? Can I represent a composite field (a field that gets serialized to multiple columns in db) in django? The hope is that this eliminates the need to having a joining query.
I don’t know of a single form field for addresses, but you can use
localflavorto validate the input and a combo ofMultiWidgetandMultiValueFieldfor creating an address field. Mine looks something like this:There is more code involved, but it is a bit much to paste in here. This info should get you headed in the right direction.
Note: as of Nov. 21, 2013 localflavor has been moved to an external package (available on PyPi).