One of my models has latitude and longitude fields which are stored in the database as floating point numbers. I like to keep it this way, because it allows me to work with them most efficiently.
I'd like the users to be able to edit them in the stock admin interface in this format: (+/-)DD MM SS.S (that's how most GPS devices present coordinates to the end user).
I've thought of three ways of implementing this:
- Use GeoDjango - too much overhead, I simply don't need the full framework only for two fields.
- Define a custom model field, somehow in this way. Seems like a lot of coding and I'm not entirely sure whether I would be able to access the floating point representation easily using the Django database interface.
- Use MultiValueField and MultiWidget - this wouldn't be an entirely bad solution, but is quite poorly documented and also involves a bit of coding and unnecessary widgets for degrees, minutes and seconds.
But ideally, I'd like to do this:
- Use a custom form field which would use the standard TextInput form widget and standard FloatField model field.
I'm sure that the to_python() method could handle text input and convert it to float. But how do I tell Django to convert float to my lat/lng representation when editing the model? And how do I stick it all together?