From d52eccd7959646190aaca00cff0c82fc5cbd55fa Mon Sep 17 00:00:00 2001 From: Romain J Date: Sat, 16 May 2020 14:40:22 +0200 Subject: [PATCH] feat(i18n): add possibility to set english description for services --- apps/gnous_eu/admin.py | 3 ++- .../migrations/0002_service_description_en.py | 18 ++++++++++++++++++ apps/gnous_eu/models.py | 1 + apps/gnous_eu/templates/services.html | 2 +- apps/gnous_eu/views.py | 3 ++- gnousEU/settings.py | 2 +- 6 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 apps/gnous_eu/migrations/0002_service_description_en.py diff --git a/apps/gnous_eu/admin.py b/apps/gnous_eu/admin.py index 4729efc..b86da0c 100644 --- a/apps/gnous_eu/admin.py +++ b/apps/gnous_eu/admin.py @@ -14,7 +14,8 @@ class ServicesAdmin(admin.ModelAdmin): "hidden", ) fieldsets = [ - ("Global", {"fields": ["name", "domain", "photo", "description"]}), + ("Global", {"fields": ["name", "domain", "photo"]}), + ("Descriptions", {"fields": ["description", "description_en"]}), ("Types", {"fields": ["sources", "hosted"]}), ("Misc", {"fields": ["hidden"]}), ] diff --git a/apps/gnous_eu/migrations/0002_service_description_en.py b/apps/gnous_eu/migrations/0002_service_description_en.py new file mode 100644 index 0000000..d5fe272 --- /dev/null +++ b/apps/gnous_eu/migrations/0002_service_description_en.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.2 on 2020-05-16 12:28 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('gnous_eu', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='service', + name='description_en', + field=models.TextField(null=True), + ), + ] diff --git a/apps/gnous_eu/models.py b/apps/gnous_eu/models.py index 927abdf..923f2ac 100644 --- a/apps/gnous_eu/models.py +++ b/apps/gnous_eu/models.py @@ -18,6 +18,7 @@ class Service(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=150) description = models.TextField() + description_en = models.TextField(null=True) photo = models.ImageField(upload_to="services") sources = models.CharField( diff --git a/apps/gnous_eu/templates/services.html b/apps/gnous_eu/templates/services.html index ceabfb4..6e65ff8 100644 --- a/apps/gnous_eu/templates/services.html +++ b/apps/gnous_eu/templates/services.html @@ -39,7 +39,7 @@ {{ service.name }} {{ service.domain }} -

{{ service.description }}

+

{% get_current_language as LANGUAGE_CODE %}{% if LANGUAGE_CODE == 'en' and service.description_en != None %}{{ service.description_en }}{% else %}{{ service.description }}{% endif %}

{% trans "Rejoindre !" %}