tim tim - 1 month ago 20
Python Question

Add a map in Django Admin

I want to add a js-map in Django admin (when you creating object).

I know about widgets, but how I understand, it must be connect to existing field (in model).

But I need a simple map (I have seen many projects like google map in admin, etc.) and they all use widgets and fields from model.

Now I use something like:

@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
class form(forms.ModelForm):
class Meta:
widgets = {
'address': MapWidget()
}


And here you can see, that I use
address
- it is object attribute.

But I need only add map to admin page and not to connect this widget to model fields.

How to do that? Thanks!

tim tim
Answer
@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
    class form(forms.ModelForm):
        address = forms.BooleanField(widget=MapWidget(),)