From fb9c78d96ae8e62d3868adc120836d8e1931f3bb Mon Sep 17 00:00:00 2001 From: moanos Date: Sun, 5 Jan 2025 21:04:27 +0100 Subject: [PATCH] feat: Add species specific URL to allow faster checking if new animals exist in this rescue org --- src/fellchensammlung/admin.py | 9 +++++++- .../migrations/0034_speciesspecificurl.py | 23 +++++++++++++++++++ src/fellchensammlung/models.py | 8 +++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/fellchensammlung/migrations/0034_speciesspecificurl.py diff --git a/src/fellchensammlung/admin.py b/src/fellchensammlung/admin.py index 02c7f89..a1b4a9c 100644 --- a/src/fellchensammlung/admin.py +++ b/src/fellchensammlung/admin.py @@ -6,7 +6,8 @@ from django.utils.html import format_html from django.urls import reverse from django.utils.http import urlencode -from .models import User, Language, Text, ReportComment, ReportAdoptionNotice, Log, Timestamp, SearchSubscription +from .models import User, Language, Text, ReportComment, ReportAdoptionNotice, Log, Timestamp, SearchSubscription, \ + SpeciesSpecificURL from .models import Animal, Species, RescueOrganization, AdoptionNotice, Location, Rule, Image, ModerationAction, \ Comment, Report, Announcement, AdoptionNoticeStatus, User, Subscriptions, BaseNotification @@ -93,6 +94,8 @@ class ReportAdoptionNoticeAdmin(admin.ModelAdmin): reported_content_link.short_description = "Reported Content" +class SpeciesSpecificURLInline(admin.StackedInline): + model = SpeciesSpecificURL @admin.register(RescueOrganization) class RescueOrganizationAdmin(admin.ModelAdmin): @@ -100,6 +103,10 @@ class RescueOrganizationAdmin(admin.ModelAdmin): list_display = ("name", "trusted", "allows_using_materials", "website") list_filter = ("allows_using_materials", "trusted",) + inlines = [ + SpeciesSpecificURLInline, + ] + @admin.register(Text) class TextAdmin(admin.ModelAdmin): diff --git a/src/fellchensammlung/migrations/0034_speciesspecificurl.py b/src/fellchensammlung/migrations/0034_speciesspecificurl.py new file mode 100644 index 0000000..445aa31 --- /dev/null +++ b/src/fellchensammlung/migrations/0034_speciesspecificurl.py @@ -0,0 +1,23 @@ +# Generated by Django 5.1.4 on 2025-01-05 19:36 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('fellchensammlung', '0033_rescueorganization_external_object_identifier_and_more'), + ] + + operations = [ + migrations.CreateModel( + name='SpeciesSpecificURL', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('url', models.URLField(verbose_name='Tierartspezifische URL')), + ('rescues_organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='fellchensammlung.rescueorganization', verbose_name='Tierschutzorganisation')), + ('species', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='fellchensammlung.species', verbose_name='Tierart')), + ], + ), + ] diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index 7d4cb5f..fcaab59 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -861,3 +861,11 @@ class Timestamp(models.Model): def ___str__(self): return f"[{self.key}] - {self.timestamp.strftime('%H:%M:%S %d-%m-%Y ')} - {self.data}" + +class SpeciesSpecificURL(models.Model): + """ + Model that allows to specify a URL for a rescue organization where a certain species can be found + """ + species = models.ForeignKey(Species, on_delete=models.CASCADE, verbose_name=_("Tierart")) + rescues_organization = models.ForeignKey(RescueOrganization, on_delete=models.CASCADE, verbose_name=_("Tierschutzorganisation")) + url = models.URLField(verbose_name=_("Tierartspezifische URL"))