{{{
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..
--
Ticket URL: <https://code.djangoproject.com/ticket/30049>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "Screenshot 2018-12-20 at 06.13.12.png" added.
broken widget
Old description:
New description:
{{{
from django.contrib.gis.db import models
admin.site.unregister(User)
admin.site.register(User, CustomUserAdmin)
}}}
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.
--
Comment (by Lars Solberg):
info about broken widget
--
Ticket URL: <https://code.djangoproject.com/ticket/30049#comment:1>
* Attachment "Screenshot 2018-12-20 at 06.26.39.png" added.
top of working widget
Comment (by Tim Graham):
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/30049#comment:2>
Comment (by Lars Solberg):
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?
--
Ticket URL: <https://code.djangoproject.com/ticket/30049#comment:3>
Comment (by Tim Graham):
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/30049#comment:4>
* stage: Unreviewed => Accepted
Comment:
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/30049#comment:5>
* Attachment "t30049.zip" added.
sample app to reproduce
* status: new => assigned
* owner: nobody => Pavel Tvrdík
--
Ticket URL: <https://code.djangoproject.com/ticket/30049#comment:6>
* has_patch: 0 => 1
* version: 2.1 => master
Comment:
[https://github.com/django/django/pull/11516 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/30049#comment:7>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/30049#comment:8>
Comment (by Mariusz Felisiak):
`GISModelAdmin` is also affected.
--
Ticket URL: <https://code.djangoproject.com/ticket/30049#comment:9>