Opened 6 years ago
Last modified 3 months ago
#30049 assigned Bug
Multiple problems using gis fields in admin inlines — at Initial Version
Reported by: | Lars Solberg | Owned by: | nobody |
---|---|---|---|
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
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..
broken widget