OSMGeoAdmin 显示 PointField 的文本区域

OSMGeoAdmin shows textarea for PointField

这是我的模型:

from django.contrib.gis.db import models
class CustomUser(AbstractBaseUser, PermissionsMixin):
    ...
    location = models.PointField(geography=True, dim=6, srid=4326, null=True)

我已经在后台注册了

from django.contrib.gis import admin
from project.accounts.models import CustomUser

admin.site.register(CustomUser, admin.OSMGeoAdmin)

但仍然有该字段的文本区域。

我哪里错了?

你可以试试 documented way:

GeoDjango also supplements the Django admin by allowing users to create and modify geometries on a JavaScript slippy map (powered by OpenLayers).

在你的 admin.py:

from django.contrib.gis import admin
from project.accounts.models import CustomUser

admin.site.register(CustomUser, admin.GeoModelAdmin)

别忘了你的 urls.py:

from django.contrib.gis import admin
from django.urls import include, path

urlpatterns = [
    path('admin/', admin.site.urls),
]