Skip to content

Commit

Permalink
Move to Django 4.0 as that is when the classes were deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Aug 26, 2024
1 parent 7ecb4e5 commit 5c14bbe
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 32 deletions.
8 changes: 4 additions & 4 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Changelog
=========

* Add Django 5.0+ fixer to rewrite ``OSMGeoAdmin`` and ``GeoModelAdmin`` classes.

`PR #484 <https://github.com/adamchainz/django-upgrade/pull/484>`__.

* Add Django 5.0+ fixer to rewrite ``format_html()`` calls without ``args`` or ``kwargs`` probably using ``str.format()`` incorrectly.

`Issue #477 <https://github.com/adamchainz/django-upgrade/issues/477>`__.

* Add Django 4.0+ fixer to rewrite ``OSMGeoAdmin`` and ``GeoModelAdmin`` classes.

`PR #484 <https://github.com/adamchainz/django-upgrade/pull/484>`__.

1.20.0 (2024-07-19)
-------------------

Expand Down
50 changes: 24 additions & 26 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -261,32 +261,6 @@ Such use cases are why calling ``format_html()`` without any arguments or keywor
-format_html("<marquee>{name}</marquee>".format(name=name))
+format_html("<marquee>{name}</marquee>", name=name)
Replace deprecated ``OSMGeoAdmin`` and ``GeoModelAdmin`` classes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Name:** ``gis_admin_deprecations``

Rewrites imports and calls for ``OSMGeoAdmin`` and ``GeoModelAdmin`` on imports and admin base classes.
The new GISModelAdmin class allows customizing the widget used for GeometryField. This is encouraged instead of deprecated GeoModelAdmin and OSMGeoAdmin.
This was deprecated in `Ticket #34609 <https://code.djangoproject.com/ticket/27674>`__.

.. code-block:: diff
-from django.contrib.gis.admin.options import OSMGeoAdmin
+from django.contrib.gis.admin.options import GISModelAdmin
-class MyAdminClass(OSMGeoAdmin):
+class MyAdminClass(GISModelAdmin):
.. code-block:: diff
-from django.contrib.gis.admin.options import GeoModelAdmin
+from django.contrib.gis.admin.options import GISModelAdmin
-class MyAdminClass(GeoModelAdmin):
+class MyAdminClass(GISModelAdmin):
Django 4.2
----------

Expand Down Expand Up @@ -474,6 +448,30 @@ Renames the undocumented ``django.contrib.admin.utils.lookup_needs_distinct`` to
+if lookup_spawns_duplicates(self.opts, search_spec):
...
Deprecated GIS ``ModelAdmin`` classes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Name:** ``gis_admin_deprecations``

Rewrites use of the deprecated classes ``OSMGeoAdmin`` and ``GeoModelAdmin`` to the new ``GISModelAdmin``.
The classes were deprecated in `Ticket #34609 <https://code.djangoproject.com/ticket/27674>`__.

.. code-block:: diff
-from django.contrib.gis.admin.options import OSMGeoAdmin
+from django.contrib.gis.admin.options import GISModelAdmin
-class MyAdminClass(OSMGeoAdmin):
+class MyAdminClass(GISModelAdmin):
.. code-block:: diff
-from django.contrib.gis.admin.options import GeoModelAdmin
+from django.contrib.gis.admin.options import GISModelAdmin
-class MyAdminClass(GeoModelAdmin):
+class MyAdminClass(GISModelAdmin):
Compatibility imports
~~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion src/django_upgrade/fixers/gis_admin_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

fixer = Fixer(
__name__,
min_version=(5, 0),
min_version=(4, 0),
)

MODULE = "django.contrib.gis.admin.options"
Expand Down
2 changes: 1 addition & 1 deletion tests/fixers/test_gis_admin_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django_upgrade.data import Settings
from tests.fixers import tools

settings = Settings(target_version=(5, 0))
settings = Settings(target_version=(4, 0))
check_noop = partial(tools.check_noop, settings=settings)
check_transformed = partial(tools.check_transformed, settings=settings)

Expand Down

0 comments on commit 5c14bbe

Please sign in to comment.