fix: options as json
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
from typing import NamedTuple
|
||||
from django.db import models
|
||||
from django.forms import Widget
|
||||
|
||||
import json
|
||||
from typing import NamedTuple
|
||||
|
||||
|
||||
class Position(NamedTuple):
|
||||
lat: float
|
||||
@@ -24,10 +26,11 @@ class MapLocationWidget(Widget):
|
||||
'leaflet/locate/L.Control.Locate.min.js',
|
||||
'map-location.js']
|
||||
|
||||
# def get_context(self, name, value, attrs):
|
||||
# context = super().get_context(name, value, attrs)
|
||||
# context['id'] = attrs.get('id')
|
||||
# return context
|
||||
def get_context(self, name, value, attrs):
|
||||
context = super().get_context(name, value, attrs)
|
||||
context['map_options'] = json.dumps(
|
||||
context['widget']['attrs'].get('options'))
|
||||
return context
|
||||
|
||||
|
||||
class LocationField(models.Field):
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
<div id="{{ widget.attrs.id }}_map" style="width: 100%; height: 400px"></div>
|
||||
<a href="" id="{{ widget.attrs.id }}_reset">Remove</a>
|
||||
<script>
|
||||
MapLocationInit("{{ widget.attrs.id }}", {{ widget.attrs.options|safe }});
|
||||
MapLocationInit("{{ widget.attrs.id }}", {{ map_options|safe }});
|
||||
</script>
|
||||
</div>
|
||||
Reference in New Issue
Block a user