django-google-maps
django-google-maps copied to clipboard
Update fields.py
Django admin Log-entries always registered a changed field for Geolocation, even when no change was made to the field.
thanks @RobKuipers! Would you be able to provide a little more information about the issue you're trying to solve? I'm not 100% sure what behavior you're seeing. Also - can you please include tests?
Hi Aaron, thanks for your reaction. I must admit I didn't see the unit-tests before. Shame on me. The problem I'm trying to solve is that when I'm changing ANY field (not just address or geolocation) on an entity, it ALWAYS triggers a change on geolocation. This is bothers me, since it shows up in the admin logging as a changed field, when in fact it was not changed. I traced this back to eq on GeoPt. I found that eq is trying to compare a 'str' with the same contents as the original GeoPt, resulting in False, when in fact they are (considering the actual contents) equal.
[edit 20221222] Thanks to having to dig a little deeper, I think I now understand what's happening: the initial data retrieved from the db was cast to a GeoPt in from_db_value. After saving a compare in Field has_changed then tries to compare a geo-string with a GeoPt, which fails. By not doing from_db_value, the initial data remains a string and thus compares correctly! But, this also means the Field is no longer returning a GeoPt, but a geo-string (hence three failing tests). Not sure which of the two solutions is best.