| 2179 | |
| 2180 | |
| 2181 | class BerryDetailSerializer(serializers.ModelSerializer): |
| 2182 | item = ItemSummarySerializer() |
| 2183 | natural_gift_type = TypeSummarySerializer() |
| 2184 | firmness = BerryFirmnessSummarySerializer(source="berry_firmness") |
| 2185 | flavors = serializers.SerializerMethodField("get_berry_flavors") |
| 2186 | |
| 2187 | class Meta: |
| 2188 | model = Berry |
| 2189 | fields = ( |
| 2190 | "id", |
| 2191 | "name", |
| 2192 | "growth_time", |
| 2193 | "max_harvest", |
| 2194 | "natural_gift_power", |
| 2195 | "size", |
| 2196 | "smoothness", |
| 2197 | "soil_dryness", |
| 2198 | "firmness", |
| 2199 | "flavors", |
| 2200 | "item", |
| 2201 | "natural_gift_type", |
| 2202 | ) |
| 2203 | |
| 2204 | @extend_schema_field( |
| 2205 | field={ |
| 2206 | "type": "array", |
| 2207 | "items": { |
| 2208 | "type": "object", |
| 2209 | "required": ["potency", "flavor"], |
| 2210 | "properties": { |
| 2211 | "potency": {"type": "integer", "examples": [10]}, |
| 2212 | "flavor": { |
| 2213 | "type": "object", |
| 2214 | "require": ["name", "url"], |
| 2215 | "properties": { |
| 2216 | "name": { |
| 2217 | "type": "string", |
| 2218 | "description": "The name of the flavor", |
| 2219 | "examples": ["spicy"], |
| 2220 | }, |
| 2221 | "url": { |
| 2222 | "type": "string", |
| 2223 | "format": "uri", |
| 2224 | "description": "The URL to get more information about the flavor", |
| 2225 | "examples": [ |
| 2226 | "https://pokeapi.co/api/v2/berry-flavor/1/" |
| 2227 | ], |
| 2228 | }, |
| 2229 | }, |
| 2230 | }, |
| 2231 | }, |
| 2232 | }, |
| 2233 | } |
| 2234 | ) |
| 2235 | def get_berry_flavors(self, obj): |
| 2236 | flavor_map_objects = BerryFlavorMap.objects.filter(berry=obj) |
| 2237 | flavor_maps = BerryFlavorMapSerializer( |
| 2238 | flavor_map_objects, many=True, context=self.context |
nothing calls this directly
no test coverage detected