Skip to content

Commit 1ecd55d

Browse files
fixed admin customization
1 parent 9d519cc commit 1ecd55d

File tree

4 files changed

+9
-33
lines changed

4 files changed

+9
-33
lines changed

README.md

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -147,32 +147,7 @@ from mapbox_location_field.spatial.admin import SpatialMapAdmin
147147
admin.site.register(SomeLocationModel, SpatialMapAdmin)
148148
```
149149
* #### Admin customization:
150-
Unfortunetly I haven't found any solution that pass [map_attrs](#map_attrs) automatically from model definition.
151-
The only working way of [customization](#customization) that works in admin panel is overriding the modelform.
152-
153-
```python
154-
from django.contrib import admin
155-
from django.forms import ModelForm
156-
from mapbox_location_field.admin import MapAdmin
157-
from mapbox_location_field.forms import LocationField
158-
159-
from .models import SomeLocationModel
160-
161-
162-
class PlaceForm(ModelForm):
163-
class Meta:
164-
model = Place fields = "__all__"
165-
location = LocationField(map_attrs={"style": "mapbox://styles/mapbox/satellite-v9"})
166-
167-
168-
class MyMapAdmin(MapAdmin):
169-
form = PlaceForm
170-
171-
admin.site.register(SomeLocationModel, MyMapAdmin)
172-
```
173-
For spatial field replace the `mapbox_location_field.admin.MapAdmin` with the `mapbox_location_field.spatial.admin.SpatialMapAdmin` and the `mapbox_location_field.forms.LocationField` with `mapbox_location_field.spatial.forms.LocationField`
174-
175-
In examples above, `SomeLocationModel` is name of your model, like in [usage section](#usage).
150+
Since `v1.7.0` admin customization should work out of the box, automatically using the `map_attrs` from model definition.
176151
177152
# AddressAutoHiddenField
178153
AddressAutoHiddenField is field for storing address. It uses AddressAutoHiddenInput which is hidden and when you place your marker on map, automatically fill itself with proper address.

mapbox_location_field/forms.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class LocationField(forms.CharField):
4444

4545
def __init__(self, *args, **kwargs):
4646
map_attrs = kwargs.pop("map_attrs", None)
47-
self.widget = MapInput(map_attrs=map_attrs, )
48-
4947
super().__init__(*args, **kwargs)
48+
49+
self.widget = MapInput(map_attrs=map_attrs, )
5050
self.error_messages = {"required": "Please pick a location, it's required", }
5151

5252
def to_python(self, value):
@@ -59,6 +59,7 @@ class AddressAutoHiddenField(forms.CharField):
5959

6060
def __init__(self, *args, **kwargs):
6161
map_id = kwargs.pop("map_id", "map")
62-
self.widget = AddressAutoHiddenInput(map_id=map_id)
6362
super().__init__(*args, **kwargs)
63+
64+
self.widget = AddressAutoHiddenInput(map_id=map_id)
6465
self.label = ""

mapbox_location_field/spatial/forms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ class SpatialLocationField(PointField):
1010

1111
def __init__(self, *args, **kwargs):
1212
map_attrs = kwargs.pop("map_attrs", None)
13-
self.widget = MapInput(map_attrs=map_attrs, )
14-
1513
super().__init__(*args, **kwargs)
14+
15+
self.widget = MapInput(map_attrs=map_attrs, )
1616
self.error_messages = {"required": "Please pick a location, it's required", }
1717

1818
def clean(self, value):

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
setup(
1212
name='django-mapbox-location-field',
13-
version='1.6.4',
13+
version='1.7.0',
1414
packages=["mapbox_location_field"],
1515
include_package_data=True,
1616
license='MIT License',
1717
description='location field with MapInput widget for picking some location',
1818
long_description=README,
1919
long_description_content_type="text/markdown",
20-
download_url="https://github.com/Simon-the-Shark/django-mapbox-location-field/archive/v1.6.4.tar.gz",
20+
download_url="https://github.com/Simon-the-Shark/django-mapbox-location-field/archive/v1.7.0.tar.gz",
2121
url='https://github.com/Simon-the-Shark/django-mapbox-location-field',
2222
author='Szymon Kowaliński',
2323
author_email='[email protected]',

0 commit comments

Comments
 (0)