wagtail-geo-widget icon indicating copy to clipboard operation
wagtail-geo-widget copied to clipboard

GEO_WIDGET_DEFAULT_LOCATION without touching the field returns None

Open marteinn opened this issue 4 years ago • 1 comments

Expected result would be that GEO_WIDGET_DEFAULT_LOCATION are set.

Description from user:

I just had to manually set the default location, by overriding the save method. I tried to set:GEO_WIDGET_DEFAULT_LOCATION = {'lat': 45.070312, 'lng': 7.6868565}  but when I save the model without touching the location, the location field is set to None (maybe I did something wrong, but with 3 lines of code in the save model I solved the problem).

marteinn avatar May 19 '20 04:05 marteinn

I tracked this down and this has been the default behavior from the beginning. I can see the use of storing the default value in the field, no matter if map is touched or not. But I can also see the use of having a None value if untouched, as to indicate the map value has not yet been filled. My plan is this:

Current solution

  • GEO_WIDGET_DEFAULT_LOCATION only effect what the map widget should show, but user interaction is required for the value to be saved, If not touched, None are stored.

New behavior

  • GEO_WIDGET_DEFAULT_LOCATION behavior are left unchanged, it only effects the map display.
  • A new setting GEO_WIDGET_SAVE_DEFAULT_LOCATION is introduced to avoid breaking changes, its False by default. Setting it to True will also save the default location as a field value as well.

marteinn avatar Jul 21 '20 06:07 marteinn