diff --git a/src/fellchensammlung/migrations/0027_alter_animal_species_andoptionnoticenotification.py b/src/fellchensammlung/migrations/0027_alter_animal_species_andoptionnoticenotification.py new file mode 100644 index 0000000..e4b8ca7 --- /dev/null +++ b/src/fellchensammlung/migrations/0027_alter_animal_species_andoptionnoticenotification.py @@ -0,0 +1,27 @@ +# Generated by Django 5.1.1 on 2024-12-14 07:57 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('fellchensammlung', '0026_alter_animal_sex'), + ] + + operations = [ + migrations.AlterField( + model_name='animal', + name='species', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='fellchensammlung.species', verbose_name='Tierart'), + ), + migrations.CreateModel( + name='AndoptionNoticeNotification', + fields=[ + ('basenotification_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='fellchensammlung.basenotification')), + ('adoption_notice', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='fellchensammlung.adoptionnotice', verbose_name='Vermittlung')), + ], + bases=('fellchensammlung.basenotification',), + ), + ] diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index 76f8bd0..85ffee4 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -753,6 +753,12 @@ class CommentNotification(BaseNotification): def url(self): return self.comment.get_absolute_url +class AndoptionNoticeNotification(BaseNotification): + adoption_notice = models.ForeignKey(AdoptionNotice, on_delete=models.CASCADE, verbose_name=_('Vermittlung')) + + @property + def url(self): + return self.adoption_notice.get_absolute_url class Subscriptions(models.Model): owner = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_('Nutzer*in')) diff --git a/src/fellchensammlung/tools/admin.py b/src/fellchensammlung/tools/admin.py index bb9dcbd..1ae786e 100644 --- a/src/fellchensammlung/tools/admin.py +++ b/src/fellchensammlung/tools/admin.py @@ -3,7 +3,8 @@ import logging from django.utils import timezone from datetime import timedelta -from fellchensammlung.models import AdoptionNotice, Location, RescueOrganization, AdoptionNoticeStatus, Log +from fellchensammlung.models import AdoptionNotice, Location, RescueOrganization, AdoptionNoticeStatus, Log, \ + AndoptionNoticeNotification from fellchensammlung.tools.misc import is_404 @@ -82,3 +83,9 @@ def deactivate_404_adoption_notices(): logging_msg = f"Automatically set Adoption Notice {adoption_notice.id} closed as link to more information returened 404" logging.info(logging_msg) Log.objects.create(action="automated", text=logging_msg) + + deactivation_message = f'Die Vermittlung [{adoption_notice.name}]({adoption_notice.get_absolute_url()}) wurde automatisch deaktiviert, da die Website unter "Mehr Informationen" nicht mehr online ist.' + AndoptionNoticeNotification.objects.create(user=adoption_notice.owner, + title="Vermittlung deaktiviert", + adoption_notice=adoption_notice, + text=deactivation_message)