Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ node_modules
Resources/nginx/ssl/*
!Resources/nginx/ssl/*.sample.*
.idea*

# Import scripts (contain sensitive database credentials)
*import*.py
*check*.py
126 changes: 126 additions & 0 deletions POKEMON_SUMMARIES_CONTRIBUTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Pokemon Summaries Contribution

This contribution adds Pokemon summaries functionality to the PokeAPI, allowing individual Pokemon to have descriptive summaries in multiple languages.

## What's Added

### 1. Database Model
- **PokemonSummary Model**: Links individual Pokemon to summary text with language support
- **Unique Constraint**: Each Pokemon can have only one summary per language
- **Migration**: `0019_pokemonsummary.py` creates the new table

### 2. API Integration
- **PokemonSummaryTextSerializer**: Serializes summary data with language information
- **Updated PokemonDetailSerializer**: Now includes a `summaries` field in Pokemon API responses
- **Multilingual Support**: Summaries can be provided in any language supported by PokeAPI

### 3. Data Import Script
- **import_summaries.py**: Script to import summaries from your PostgreSQL database
- **Flexible Query**: Easily adaptable to your existing database schema
- **Error Handling**: Graceful handling of missing Pokemon or languages

### 4. Tests
- **PokemonSummaryTestCase**: Tests for model creation and unique constraints
- **Integration Tests**: Ensures the functionality works as expected

## API Usage

Once summaries are imported, they will be available in the Pokemon detail endpoint:

```bash
GET /api/v2/pokemon/pikachu/
```

Response will include:
```json
{
"id": 25,
"name": "pikachu",
"summaries": [
{
"summary": "Pikachu is an Electric-type Pokémon known for its yellow fur and red cheeks.",
"language": {
"name": "en",
"url": "https://pokeapi.co/api/v2/language/9/"
}
}
],
// ... other Pokemon data
}
```

## Setup Instructions

### 1. Apply the Migration
```bash
python3 manage.py migrate pokemon_v2
```

### 2. Import Your Summaries
```bash
python3 import_summaries.py \
--host your_production_host \
--port 5432 \
--database your_database \
--user your_username \
--password your_password
```

### 3. Customize the Import Script
You may need to modify the SQL query in `import_summaries.py` to match your database schema:

```python
query = """
SELECT
pokemon_name, -- Your Pokemon name column
language_code, -- Your language code column
summary_text -- Your summary text column
FROM your_summaries_table
WHERE summary_text IS NOT NULL AND summary_text != ''
"""
```

## Database Schema

The new `pokemon_summary` table has the following structure:

```sql
CREATE TABLE pokemon_summary (
id SERIAL PRIMARY KEY,
summary TEXT NOT NULL,
language_id INTEGER REFERENCES language(id),
pokemon_id INTEGER REFERENCES pokemon(id),
UNIQUE(pokemon_id, language_id)
);
```

## Testing

Run the tests to ensure everything works:

```bash
python3 manage.py test pokemon_v2.test_models.PokemonSummaryTestCase
```

## Contributing Guidelines

This contribution follows PokeAPI's existing patterns:

1. **Model Structure**: Uses existing abstract base classes (`HasPokemon`, `HasLanguage`)
2. **Serializer Pattern**: Follows the same pattern as other multilingual content
3. **API Integration**: Seamlessly integrates with existing Pokemon endpoints
4. **Testing**: Includes comprehensive tests
5. **Documentation**: Well-documented code and usage instructions

## Future Enhancements

Potential future improvements:
- Admin interface for managing summaries
- Bulk import/export functionality
- Summary validation and moderation
- Integration with existing flavor text system

## Questions?

If you have questions about this contribution or need help adapting it to your specific database schema, please feel free to ask!

Loading