From 22268a46db9f3c0603a76bf6419db8e5da8c3e0b Mon Sep 17 00:00:00 2001 From: Juha Louhiranta Date: Wed, 31 Jul 2024 14:39:27 +0300 Subject: [PATCH] refactor: fix parler deprecation warning Please change apiscopetranslation.master to a parler.fields.TranslationsForeignKey field to support translations in data migrations. Refs: HP-2441 --- .../0004_alter_apiscopetranslation_master.py | 26 +++++++++++++++++++ oidc_apis/models.py | 4 +-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 oidc_apis/migrations/0004_alter_apiscopetranslation_master.py diff --git a/oidc_apis/migrations/0004_alter_apiscopetranslation_master.py b/oidc_apis/migrations/0004_alter_apiscopetranslation_master.py new file mode 100644 index 00000000..8d6f15ce --- /dev/null +++ b/oidc_apis/migrations/0004_alter_apiscopetranslation_master.py @@ -0,0 +1,26 @@ +# Generated by Django 4.2.14 on 2024-07-31 11:37 + +from django.db import migrations +import django.db.models.deletion +import parler.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ("oidc_apis", "0003_api_backchannel_logout_url"), + ] + + operations = [ + migrations.AlterField( + model_name="apiscopetranslation", + name="master", + field=parler.fields.TranslationsForeignKey( + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="translations", + to="oidc_apis.apiscope", + verbose_name="API scope", + ), + ), + ] diff --git a/oidc_apis/models.py b/oidc_apis/models.py index 457e8ee5..ec3a1baf 100644 --- a/oidc_apis/models.py +++ b/oidc_apis/models.py @@ -5,7 +5,7 @@ from django.utils.translation import gettext_lazy as _ from multiselectfield import MultiSelectField from oidc_provider.models import Client -from parler.fields import TranslatedField +from parler.fields import TranslatedField, TranslationsForeignKey from parler.managers import TranslatableQuerySet from parler.models import TranslatableModel, TranslatedFieldsModel @@ -193,7 +193,7 @@ def _get_required_scopes(cls, scopes): class ApiScopeTranslation(TranslatedFieldsModel): - master = models.ForeignKey( + master = TranslationsForeignKey( ApiScope, related_name='translations', null=True, on_delete=models.CASCADE, verbose_name=_("API scope"))