diff --git a/src/fellchensammlung/api/serializers.py b/src/fellchensammlung/api/serializers.py index cd0fff8..9f8dbf2 100644 --- a/src/fellchensammlung/api/serializers.py +++ b/src/fellchensammlung/api/serializers.py @@ -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() diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index f3b0853..0d15d93 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -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"))