| 602 | |
| 603 | |
| 604 | class RegionDetailSerializer(serializers.ModelSerializer): |
| 605 | names = RegionNameSerializer(many=True, read_only=True, source="regionname") |
| 606 | locations = LocationSummarySerializer(many=True, read_only=True, source="location") |
| 607 | version_groups = serializers.SerializerMethodField("get_region_version_groups") |
| 608 | pokedexes = PokedexSummarySerializer(many=True, read_only=True, source="pokedex") |
| 609 | main_generation = GenerationSummarySerializer(read_only=True, source="generation") |
| 610 | |
| 611 | class Meta: |
| 612 | model = Region |
| 613 | fields = ( |
| 614 | "id", |
| 615 | "name", |
| 616 | "locations", |
| 617 | "main_generation", |
| 618 | "names", |
| 619 | "pokedexes", |
| 620 | "version_groups", |
| 621 | ) |
| 622 | |
| 623 | @extend_schema_field( |
| 624 | field={ |
| 625 | "type": "array", |
| 626 | "items": { |
| 627 | "type": "object", |
| 628 | "required": ["name", "url"], |
| 629 | "properties": { |
| 630 | "name": {"type": "string", "examples": ["red-blue"]}, |
| 631 | "url": { |
| 632 | "type": "string", |
| 633 | "format": "uri", |
| 634 | "examples": ["https://pokeapi.co/api/v2/version-group/1/"], |
| 635 | }, |
| 636 | }, |
| 637 | }, |
| 638 | } |
| 639 | ) |
| 640 | def get_region_version_groups(self, obj): |
| 641 | vg_regions = VersionGroupRegion.objects.filter(region=obj) |
| 642 | data = VersionGroupRegionSerializer( |
| 643 | vg_regions, many=True, context=self.context |
| 644 | ).data |
| 645 | groups = [] |
| 646 | |
| 647 | for group in data: |
| 648 | groups.append(group["version_group"]) |
| 649 | |
| 650 | return groups |
| 651 | |
| 652 | |
| 653 | ############################ |
nothing calls this directly
no test coverage detected