Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GeoModelAdminMixin #1982

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions django-stubs/contrib/gis/admin/options.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
from typing import Any
from typing import Any, ClassVar

from django.contrib.admin import ModelAdmin
from django.contrib.gis.forms import BaseGeometryWidget
from django.contrib.gis.forms import OSMWidget
from django.db.models import Field
from django.forms.fields import Field as FormField
from django.forms.widgets import Media
from django.http import HttpRequest

spherical_mercator_srid: int

class GISModelAdmin(ModelAdmin):
gis_widget: BaseGeometryWidget
gis_widget_kwargs: dict[str, Any]
class GeoModelAdminMixin:
gis_widget: ClassVar[type[OSMWidget]]
gis_widget_kwargs: ClassVar[dict[str, Any]]
def formfield_for_dbfield(self, db_field: Field, request: HttpRequest, **kwargs: Any) -> FormField: ...

class GISModelAdmin(GeoModelAdminMixin, ModelAdmin): ...

class GeoModelAdmin(ModelAdmin):
default_lon: int
Expand Down
3 changes: 3 additions & 0 deletions scripts/stubtest/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,6 @@ django.urls.resolvers.URLPattern.lookup_str
django.urls.resolvers.URLResolver.url_patterns
django.urls.resolvers.URLResolver.urlconf_module
django.utils.connection.BaseConnectionHandler.settings

# Potential mypy bug with metaclass
q0w marked this conversation as resolved.
Show resolved Hide resolved
django.contrib.gis.admin.options.GeoModelAdminMixin.gis_widget
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also might be a bug with our plugin. Can you please try with and without ClassVar?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In both cases it fails

3 changes: 0 additions & 3 deletions scripts/stubtest/allowlist_todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ django.contrib.flatpages.models.FlatPage.template_name
django.contrib.flatpages.models.FlatPage.title
django.contrib.flatpages.models.FlatPage.url
django.contrib.gis.admin.GISModelAdmin
django.contrib.gis.admin.GISModelAdmin.gis_widget
django.contrib.gis.admin.GeoModelAdmin
django.contrib.gis.admin.ModelAdmin
django.contrib.gis.admin.ModelAdmin.log_addition
Expand All @@ -237,9 +236,7 @@ django.contrib.gis.admin.TabularInline
django.contrib.gis.admin.action
django.contrib.gis.admin.display
django.contrib.gis.admin.options.GISModelAdmin
django.contrib.gis.admin.options.GISModelAdmin.gis_widget
django.contrib.gis.admin.options.GeoModelAdmin
django.contrib.gis.admin.options.GeoModelAdminMixin
django.contrib.gis.admin.options.OSMGeoAdmin
django.contrib.gis.admin.site
django.contrib.gis.db.backends.base.features.BaseSpatialFeatures.can_alter_geometry_field
Expand Down