From 7c0ba18824394835d1f02cb2ccdbf3b2c88f6338 Mon Sep 17 00:00:00 2001 From: aeltheos Date: Mon, 11 Oct 2021 20:40:48 +0200 Subject: [PATCH] extended photologue photo to add an owner field --- photo21/locale/fr/LC_MESSAGES/django.po | 22 ++++++------- photologue_custom/admin.py | 20 ++++++++++-- .../migrations/0002_photoextended.py | 29 +++++++++++++++++ photologue_custom/models.py | 31 +++++++++++++++++-- 4 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 photologue_custom/migrations/0002_photoextended.py diff --git a/photo21/locale/fr/LC_MESSAGES/django.po b/photo21/locale/fr/LC_MESSAGES/django.po index 9dba126..cc9f517 100644 --- a/photo21/locale/fr/LC_MESSAGES/django.po +++ b/photo21/locale/fr/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-10-11 11:48+0000\n" +"POT-Creation-Date: 2021-10-11 18:38+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -18,11 +18,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" -#: accounts/forms.py:9 -msgid "Email address" -msgstr "Adresse email" - -#: accounts/forms.py:13 +#: photo21/forms.py:12 msgid "" "Please enter a valid email address ending with `@crans.org` or `@ens-paris-" "saclay.fr`." @@ -30,23 +26,23 @@ msgstr "" "Veuillez entrer une adresse email valide finissant par `@crans.org` ou `@ens-" "paris-saclay.fr`." -#: accounts/forms.py:25 +#: photo21/forms.py:23 msgid "Must end with `@crans.org` or `@ens-paris-saclay.fr`." msgstr "Doit finir par `@crans.org` ou `@ens-paris-saclay.fr`." -#: photo21/settings.py:144 +#: photo21/settings.py:143 msgid "German" msgstr "" -#: photo21/settings.py:145 +#: photo21/settings.py:144 msgid "English" msgstr "" -#: photo21/settings.py:146 +#: photo21/settings.py:145 msgid "Spanish" msgstr "" -#: photo21/settings.py:147 +#: photo21/settings.py:146 msgid "French" msgstr "" @@ -178,6 +174,10 @@ msgstr "Inscription" msgid "Connected as" msgstr "Connecté en tant que" +#: photologue_custom/models.py:39 +msgid "owner" +msgstr "propriétaire" + #: photologue_custom/templates/photologue/gallery_archive.html:4 #: photologue_custom/templates/photologue/gallery_archive.html:9 msgid "Latest photo galleries" diff --git a/photologue_custom/admin.py b/photologue_custom/admin.py index a38f925..cfd8ddf 100644 --- a/photologue_custom/admin.py +++ b/photologue_custom/admin.py @@ -1,8 +1,9 @@ from django.contrib import admin from photologue.admin import GalleryAdmin as GalleryAdminDefault -from photologue.models import Gallery +from photologue.admin import PhotoAdmin as PhotoAdminDefault +from photologue.models import Gallery, Photo -from .models import GalleryExtended +from .models import GalleryExtended, PhotoExtended class GalleryExtendedInline(admin.StackedInline): @@ -18,5 +19,20 @@ class GalleryAdmin(GalleryAdminDefault): inlines = [GalleryExtendedInline, ] +class PhotoExtendedInline(admin.StackedInline): + model = PhotoExtended + can_delete = True + + +class PhotoAdmin(PhotoAdminDefault): + """ + Define our new one-to-one model as an inline of Photologue's Photo + model. + """ + inlines = [PhotoExtendedInline, ] + + admin.site.unregister(Gallery) +admin.site.unregister(Photo) admin.site.register(Gallery, GalleryAdmin) +admin.site.register(Photo, PhotoAdmin) diff --git a/photologue_custom/migrations/0002_photoextended.py b/photologue_custom/migrations/0002_photoextended.py new file mode 100644 index 0000000..2b1ecef --- /dev/null +++ b/photologue_custom/migrations/0002_photoextended.py @@ -0,0 +1,29 @@ +# Generated by Django 2.2.24 on 2021-10-11 18:40 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('photologue', '0011_auto_20190223_2138'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('photologue_custom', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='PhotoExtended', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='owner')), + ('photo', models.OneToOneField(on_delete='cascade', related_name='extented', to='photologue.Photo')), + ], + options={ + 'verbose_name': 'Extra fields', + 'verbose_name_plural': 'Extra fields', + }, + ), + ] diff --git a/photologue_custom/models.py b/photologue_custom/models.py index 377f83b..4a4469a 100644 --- a/photologue_custom/models.py +++ b/photologue_custom/models.py @@ -1,6 +1,8 @@ from django.db import models +from django.conf import settings from taggit.managers import TaggableManager -from photologue.models import Gallery +from photologue.models import Gallery, Photo +from django.utils.translation import gettext_lazy as _ class GalleryExtended(models.Model): @@ -15,8 +17,31 @@ class GalleryExtended(models.Model): tags = TaggableManager(blank=True) class Meta: - verbose_name = u'Extra fields' - verbose_name_plural = u'Extra fields' + verbose_name = 'Extra fields' + verbose_name_plural = 'Extra fields' def __str__(self): return self.gallery.title + + +class PhotoExtended(models.Model): + # Extend Photologue Photo model. + photo = models.OneToOneField( + Photo, + related_name='extented', + on_delete='cascade' + ) + + # Add a owner field to PhotoExtended + owner = models.ForeignKey( + settings.AUTH_USER_MODEL, + on_delete=models.CASCADE, + verbose_name=_("owner"), + ) + + class Meta: + verbose_name = 'Extra fields' + verbose_name_plural = 'Extra fields' + + def __str__(self): + return str(self.photo)