Opened 6 years ago
Last modified 3 months ago
#30049 assigned Bug
GIS widgets don't initialize properly after clicking "Add another" in admin inlines
Reported by: | Lars Solberg | Owned by: | Claude Paroz |
---|---|---|---|
Component: | GIS | Version: | dev |
Severity: | Normal | Keywords: | gis, admin |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
My goal is to use a field that looks like this:
from django.contrib.gis.db import models class FavoriteLocation(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) location = models.PointField()
as an extra field on a User. The field-type works on other models, so everything is setup correctly.
However, getting it as a inline is problematic because it doesnt render correctly in the admin.
The admin code looks like this:
from django.contrib.auth.admin import UserAdmin from django.contrib.gis import admin class FavoriteLocationInline(admin.StackedInline): model = FavoriteLocation extra = 1 class CustomUserAdmin(UserAdmin): inlines = (FavoriteLocationInline,) admin.site.unregister(User) admin.site.register(User, CustomUserAdmin)
however, the widget for displaying the field looks blank (see screenshot).
In the doc, It sais I should use "admin.OSMGeoAdmin" for my admin class. However, that don't change anything.
Nor changing it to "class CustomUserAdmin(admin.OSMGeoAdmin, UserAdmin).
If I click add "another favorite location", I will also get a text-area field instead of the widget.
Trying to save the model with this broken widget gives me a "GDALException" (django.contrib.gis.gdal.error.GDALException: OGR failure.)
Note that this widget works on other admin-pages I have..
Also note that the broken widget is black because it is all zoomed in on 0, 0.. However, it also misses some elements in the upper right corner.
I am seeing no errors in the browser console.
Attachments (3)
Change History (16)
by , 6 years ago
Attachment: | Screenshot 2018-12-20 at 06.13.12.png added |
---|
comment:2 by , 6 years ago
I think you should try inheriting from OSMGeoAdmin
rather than UserAdmin
. You'll have to copy the parts of UserAdmin
that you want into your subclass, I imagine. I imagine this use case isn't too common and I'm not sure if there's anything Django could do to make it easier.
This looks more like a usage question than a bug in Django, but if you have some idea about what could be done, feel free to let us know.
comment:3 by , 6 years ago
I still coulnt get it to work.
I tried using one I have working as an inline, then the inlined version stopped working as well.
So this happens when I am using inlines..
The html to render the widgets are wastly different..
- Inlined version @ https://gist.github.com/xeor/968ad1c597c59c432b4a3588b87f2178
- Normal version @ https://gist.github.com/xeor/84a374d57b89adeef5b37513b4409667
In this case, I have taken out the useradmin part, and have made a normal admin interface..
from django.contrib.gis import admin from .models import Other, Spot class SpotInline(admin.StackedInline): model = Spot extra = 1 class OtherAdmin(admin.OSMGeoAdmin): inlines = (SpotInline,) admin.site.register(Other, OtherAdmin)
OtherAdmin now has the map as a normal widget (works), and one as an inline (doesnt work).
I can see in eg https://github.com/django/django/blob/master/django/contrib/gis/templates/gis/admin/openlayers.html that there are some references around to example {{ id }}_map
.. Will id
be correct when this is using an inline?
comment:4 by , 6 years ago
It's possible that inline GIS widgets are broken. I'm not sure if the Django tests cover that. Can you put together a small sample project that reproduces the issue? You could also check with if it works with older versions (2.0.x, 1.11.x, etc.) of Django.
comment:5 by , 6 years ago
Summary: | Multiple problems using gis fields in admin inlines → GIS widgets don't initialize properly after clicking "Add another" in admin inlines |
---|---|
Triage Stage: | Unreviewed → Accepted |
Using the attached sample project, I can reproduce the problem that clicking "Add another City" on the admin's state change form doesn't initialize the new widget properly (textarea instead of the openlayers widget). It doesn't seem to be a new issue -- I reproduced back as far as I tested (Django 1.11).
I'm not sure if the "missing elements in the upper right corner" part of this report is valid... when using PointField
in a non-inline admin, those elements don't appear either. Are they not applicable to PointField
? In any case, a bug report should be limited to one issue so let's keep this ticket limited to the "Add another" initialization and open addition tickets if more issues remain.
comment:6 by , 6 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:8 by , 5 years ago
Patch needs improvement: | set |
---|
comment:10 by , 3 months ago
Needs tests: | set |
---|---|
Owner: | changed from | to
comment:12 by , 3 months ago
Patch needs improvement: | set |
---|
comment:13 by , 3 months ago
I think it would be better to wait for #25706 before finishing this one.
broken widget