From 96ae80b7f0ec58f23b11b16c4fc511ece4275df2 Mon Sep 17 00:00:00 2001 From: Dylan Verheul Date: Wed, 24 Apr 2024 13:43:29 +0200 Subject: [PATCH 1/2] Remove references to unsupported Django versions --- modeltrans/manager.py | 6 +----- tests/test_models.py | 13 +++---------- tests/test_translating.py | 7 +------ 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/modeltrans/manager.py b/modeltrans/manager.py index 134979a..13be904 100644 --- a/modeltrans/manager.py +++ b/modeltrans/manager.py @@ -1,4 +1,3 @@ -from django import VERSION as DJANGO_VERSION from django.core.exceptions import FieldDoesNotExist from django.db.models import Count, Func, Manager, Q, QuerySet from django.db.models.constants import LOOKUP_SEP @@ -193,10 +192,7 @@ def _rewrite_expression(self, expr): def _rewrite_Q(self, q): if isinstance(q, Q): - if DJANGO_VERSION < (4, 2): - factory = Q._new_instance - else: - factory = Q.create + factory = Q.create return factory( list(self._rewrite_Q(child) for child in q.children), connector=q.connector, diff --git a/tests/test_models.py b/tests/test_models.py index 299fc59..2954283 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,4 +1,4 @@ -from django import VERSION as DJANGO_VERSION + from django.core.exceptions import ValidationError from django.db import DataError, models, transaction from django.test import TestCase, override_settings @@ -137,18 +137,11 @@ def test_creating_with_nonexisting_field(self): Blogs have titles, not names, so trying to add something with a name should raise an eror. """ - if DJANGO_VERSION < (4, 1): - expected_message = "Blog() got an unexpected keyword argument 'name'" - else: - expected_message = "Blog() got unexpected keyword arguments: 'name'" - + expected_message = "Blog() got unexpected keyword arguments: 'name'" with self.assertRaisesMessage(TypeError, expected_message): Blog.objects.create(name="Falcon") - if DJANGO_VERSION < (4, 1): - expected_message = "Blog() got an unexpected keyword argument 'name_nl'" - else: - expected_message = "Blog() got unexpected keyword arguments: 'name_nl'" + expected_message = "Blog() got unexpected keyword arguments: 'name_nl'" with self.assertRaisesMessage(TypeError, expected_message): Blog.objects.create(title="Falcon", name_nl="Valk") diff --git a/tests/test_translating.py b/tests/test_translating.py index bf8c2ae..e586f10 100644 --- a/tests/test_translating.py +++ b/tests/test_translating.py @@ -1,4 +1,3 @@ -from django import VERSION as DJANGO_VERSION from django.core.exceptions import ImproperlyConfigured, ValidationError from django.db import models from django.test import TestCase @@ -227,11 +226,7 @@ class Meta: self.assertFalse(hasattr(m, "title_i18n")) self.assertFalse(hasattr(m, "title_en")) - if DJANGO_VERSION < (4, 1): - expected_message = "TestModel4() got an unexpected keyword argument 'title_nl'" - else: - expected_message = "TestModel4() got unexpected keyword arguments: 'title_nl'" - + expected_message = "TestModel4() got unexpected keyword arguments: 'title_nl'" with self.assertRaisesMessage(TypeError, expected_message): TestModel4(title="bar", title_nl="foo") From ee055300b81dd2c2c04e2cb48e5c8b28210d472b Mon Sep 17 00:00:00 2001 From: Dylan Verheul Date: Wed, 24 Apr 2024 13:44:36 +0200 Subject: [PATCH 2/2] Black --- tests/test_models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_models.py b/tests/test_models.py index 2954283..35bb934 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,4 +1,3 @@ - from django.core.exceptions import ValidationError from django.db import DataError, models, transaction from django.test import TestCase, override_settings