# Podcast System Refactoring Summary ## Overview تغییرات اساسی در معماری سیستم podcast برای همسان‌سازی با ساختار Video ## Changes Made ### 1. Model Changes #### ❌ Removed: - **PodcastInCollection** model (مدل منسوخ شده که پادکست‌ها را مستقیماً به Collection ها متصل می‌کرد) - **podcasts** field from PodcastCollection (فیلد ManyToMany که پادکست‌ها را به Collection متصل می‌کرد) - **collections** field from Podcast (فیلد ManyToMany که پادکست‌ها را به Collection متصل می‌کرد) #### ✅ Added/Enhanced: - **PodcastPlaylistInCollection** model (معماری صحیح که Playlist ها را به Collection متصل می‌کند) - **PodcastPlaylist** enhanced with full fields: - slug, slogan, description, thumbnail - categories (ManyToMany to PodcastCategory) - collections (ManyToMany through PodcastPlaylistInCollection) - order, status, view_count, total_time - increment_view_count() and calculate_total_time() methods ### 2. Architecture Improvement **قبل:** ``` PodcastCollection --[PodcastInCollection]--> Podcast ``` **بعد:** ``` PodcastCollection --[PodcastPlaylistInCollection]--> PodcastPlaylist --[PlaylistItem]--> Podcast ``` این تغییر باعث می‌شود: - Collection ها شامل Playlist باشند (نه مستقیماً Podcast) - سازماندهی بهتر محتوا - معماری منطقی‌تر و قابل نگهداری‌تر - همسان با ساختار Video ### 3. Admin Panel Updates **apps/podcast/admin.py:** - تغییر `PodcastInCollectionInline` به `PodcastPlaylistInCollectionInlineForCollection` - اضافه شدن `PodcastPlaylistInCollectionInline` برای PodcastPlaylist admin - تغییر `count_podcasts()` به `count_playlists()` در Collection و Category admins - اضافه شدن فیلدهای جدید به PodcastPlaylistAdmin - محاسبه خودکار total_time در save_model ### 4. Serializers Updates **apps/podcast/serializers.py:** - تغییر `podcast_count` به `playlist_count` در PodcastCategoryListSerializer - اضافه شدن **PodcastPlaylistListSerializer** جدید - اضافه شدن **PodcastPlaylistDetailSerializer** جدید با: - categories, thumbnail, bookmark - user_rate, average_rate - podcasts (لیست پادکست‌های درون playlist) - total_time_formatted - تغییر MiddlePodcastCollectionSerializer برای استفاده از playlists ### 5. Migration **Migration File:** `0003_refactor_podcast_models.py` - ایجاد PodcastPlaylistInCollection - حذف فیلد collections از podcast - حذف فیلد podcasts از podcastcollection - اضافه فیلدهای جدید به podcastplaylist - حذف مدل PodcastInCollection ### 6. Management Commands #### cleanup_podcast_data.py حذف تمام داده‌های PodcastCategory، PodcastCollection، و PodcastPlaylist (بدون حذف Podcast) **Usage:** ```bash python manage.py cleanup_podcast_data --confirm ``` #### create_podcast_playlists.py ایجاد 10 پلی‌لیست با محتوای روسی درباره پیامبران و امامان **Usage:** ```bash python manage.py create_podcast_playlists python manage.py create_podcast_playlists --dry-run # for testing ``` **Playlists:** 1. Лекции о Пророке Мухаммаде (да благословит его Аллах) 2. Истории пророков в аудио формате 3. Имам Али: Аудио наставления 4. Имам Хусейн: Аудио о Кербеле 5. Двенадцать Имамов: Аудио курс 6. Фатима аз-Захра: Аудио лекции 7. Имам Махди: Аудио о ожидании 8. Чудеса пророков: Аудио рассказы 9. Нравственность Ахль аль-Байт: Аудио 10. Имам Риза: Аудио наследие ### 7. API Changes **URLs to add/update** (similar to video app): ```python # Suggested new endpoints path('playlists/', PodcastPlaylistListAPIView.as_view(), name='playlist-list'), path('playlists//', PodcastPlaylistDetailAPIView.as_view(), name='playlist-detail'), ``` **Expected API responses:** **GET /api/podcast/playlists/** - Filter by: category, collection, is_bookmark, search - Returns: List of playlists with thumbnail, slogan, view_count, total_time **GET /api/podcast/playlists//** - Returns: Full playlist details with podcasts, categories, ratings, bookmarks **GET /api/podcast/collections/** - Returns: Collections with playlists (not direct podcasts) ### 8. Next Steps 1. ✅ Models refactored 2. ✅ Admin panel updated 3. ✅ Serializers updated 4. ✅ Migration created (needs to be applied when DB is available) 5. ✅ Management commands created 6. 🔄 Views need to be updated (add PodcastPlaylistListAPIView and PodcastPlaylistDetailAPIView) 7. 🔄 URLs need to be updated 8. 🔄 Documentation needs to be updated 9. 🔄 Test when database is available ## Important Notes - ⚠️ PodcastInCollection model is completely removed - ✅ Podcasts are preserved - no podcast data was lost - ✅ New architecture matches Video app structure - ✅ Admin panel updated to reflect new structure - 🔄 API endpoints need minor updates for playlist support - 🔄 Migration will run when database connection is restored ## Commands for Testing (when DB is available) ```bash # Apply migration python manage.py migrate podcast # Clean up old data python manage.py cleanup_podcast_data --confirm # Create 10 playlists with all podcasts python manage.py create_podcast_playlists # Check current state python manage.py shell -c " from apps.podcast.models import Podcast, PodcastPlaylist, PodcastCollection, PodcastCategory print(f'Podcasts: {Podcast.objects.count()}') print(f'Playlists: {PodcastPlaylist.objects.count()}') print(f'Collections: {PodcastCollection.objects.count()}') print(f'Categories: {PodcastCategory.objects.count()}') " ``` ## Comparison with Video App تمام تغییرات مشابه با آنچه برای اپ video انجام شد: | Feature | Video App | Podcast App | |---------|-----------|-------------| | Playlist Model | VideoPlaylist | PodcastPlaylist ✅ | | Playlist-Collection Link | VideoPlaylistInCollection | PodcastPlaylistInCollection ✅ | | Item Model | PlaylistItem | PlaylistItem ✅ | | Remove Direct Link | VideoInCollection removed | PodcastInCollection removed ✅ | | Admin Integration | Complete | Complete ✅ | | Serializers | Complete | Complete ✅ | | Management Commands | cleanup + create | cleanup + create ✅ | | Documentation | Updated | Need to update 🔄 |