Commit 1dc41d83 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Merge branch '426-translations-album-titles' into 'master'

Made album titles multilingual

Closes #426

See merge request !474
parents 73ddf51c 7c6848de
......@@ -10,6 +10,7 @@ from django.core.exceptions import ValidationError
from django.core.files.base import ContentFile
from django.utils.translation import ugettext_lazy as _
from utils.translation import TranslatedModelAdmin
from .models import Album, Photo
......@@ -68,12 +69,14 @@ def save_photo(request, archive_file, photo, album):
photo_obj.save()
class AlbumAdmin(admin.ModelAdmin):
class AlbumAdmin(TranslatedModelAdmin):
list_display = ('title', 'date', 'hidden', 'shareable')
fields = ('title', 'slug', 'date', 'hidden', 'shareable',
'_cover')
search_fields = ('title', 'date')
list_filter = ('hidden', 'shareable')
date_hierarchy = 'date'
prepopulated_fields = {'slug': ('date', 'title',)}
prepopulated_fields = {'slug': ('date', 'title_en',)}
form = AlbumForm
def save_model(self, request, obj, form, change):
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-05-03 19:01
from __future__ import unicode_literals
from django.db import migrations, models
def add_english_titles(apps, schema_editor):
Album = apps.get_model('photos', 'Album')
for album in Album.objects.all():
album.title_en = album.title_nl
album.save()
class Migration(migrations.Migration):
atomic = False
dependencies = [
('photos', '0007_auto_20170218_2142'),
]
operations = [
migrations.RenameField(
model_name='album',
old_name='title',
new_name='title_nl',
),
migrations.AlterField(
model_name='album',
name='title_nl',
field=models.CharField(default='', max_length=200, verbose_name='title (NL)'),
preserve_default=False,
),
migrations.AddField(
model_name='album',
name='title_en',
field=models.CharField(default='', max_length=200, verbose_name='title (EN)'),
preserve_default=False,
),
migrations.AlterModelOptions(
name='album',
options={'ordering': ('-date', 'title_en')},
),
migrations.RunPython(
code=add_english_titles,
),
]
......@@ -9,6 +9,8 @@ from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
from PIL import Image
from utils.translation import ModelTranslateMeta, MultilingualField
COVER_FILENAME = 'cover.jpg'
......@@ -65,9 +67,10 @@ class Photo(models.Model):
ordering = ('file', )
class Album(models.Model):
title = models.CharField(
verbose_name=_('title'),
class Album(models.Model, metaclass=ModelTranslateMeta):
title = MultilingualField(
models.CharField,
_("title"),
max_length=200,
)
......@@ -133,4 +136,4 @@ class Album(models.Model):
.encode('utf-8')).hexdigest()
class Meta:
ordering = ('-date', 'title')
ordering = ('-date', 'title_en')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment