feat: add species specific url to api

This commit is contained in:
2026-01-20 21:03:08 +01:00
parent dfa44ea0c6
commit c324394949
2 changed files with 17 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
from ..models import Animal, RescueOrganization, AdoptionNotice, Species, Image, Location
from ..models import Animal, RescueOrganization, AdoptionNotice, Species, Image, Location, SpeciesSpecificURL
from rest_framework import serializers
import math
@@ -144,12 +144,23 @@ class AnimalGetSerializer(serializers.ModelSerializer):
fields = "__all__"
class SpeciesSpecificURLSerializer(serializers.ModelSerializer):
class Meta:
model = SpeciesSpecificURL
fields = "__all__"
class RescueOrganizationSerializer(serializers.ModelSerializer):
url = serializers.SerializerMethodField()
species_specific_urls = SpeciesSpecificURLSerializer(many=True, read_only=True)
class Meta:
model = RescueOrganization
exclude = ["internal_comment", "allows_using_materials"]
fields = ('id', 'name', 'url', 'trusted', 'location_string', 'instagram', "facebook", "fediverse_profile",
"email", "phone_number", "website", "updated_at", "created_at", "last_checked", "description",
"external_source_identifier", "external_object_identifier", "exclude_from_check",
"regular_check_status", "ongoing_communication", "twenty_id", "location", "parent_org", "specializations",
"species_specific_urls")
def get_url(self, obj):
return obj.get_absolute_url()

View File

@@ -1088,8 +1088,10 @@ class SpeciesSpecificURL(models.Model):
verbose_name_plural = _("Tierartspezifische URLs")
species = models.ForeignKey(Species, on_delete=models.CASCADE, verbose_name=_("Tierart"))
rescue_organization = models.ForeignKey(RescueOrganization, on_delete=models.CASCADE,
verbose_name=_("Tierschutzorganisation"))
rescue_organization = models.ForeignKey(RescueOrganization,
on_delete=models.CASCADE,
verbose_name=_("Tierschutzorganisation"),
related_name="species_specific_urls")
url = models.URLField(verbose_name=_("Tierartspezifische URL"))