You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
6.6 KiB
6.6 KiB
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:
python manage.py cleanup_podcast_data --confirm
create_podcast_playlists.py
ایجاد 10 پلیلیست با محتوای روسی درباره پیامبران و امامان
Usage:
python manage.py create_podcast_playlists
python manage.py create_podcast_playlists --dry-run # for testing
Playlists:
- Лекции о Пророке Мухаммаде (да благословит его Аллах)
- Истории пророков в аудио формате
- Имам Али: Аудио наставления
- Имам Хусейн: Аудио о Кербеле
- Двенадцать Имамов: Аудио курс
- Фатима аз-Захра: Аудио лекции
- Имам Махди: Аудио о ожидании
- Чудеса пророков: Аудио рассказы
- Нравственность Ахль аль-Байт: Аудио
- Имам Риза: Аудио наследие
7. API Changes
URLs to add/update (similar to video app):
# Suggested new endpoints
path('playlists/', PodcastPlaylistListAPIView.as_view(), name='playlist-list'),
path('playlists/<slug:slug>/', 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
- ✅ Models refactored
- ✅ Admin panel updated
- ✅ Serializers updated
- ✅ Migration created (needs to be applied when DB is available)
- ✅ Management commands created
- 🔄 Views need to be updated (add PodcastPlaylistListAPIView and PodcastPlaylistDetailAPIView)
- 🔄 URLs need to be updated
- 🔄 Documentation needs to be updated
- 🔄 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)
# 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 🔄 |