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.
5.4 KiB
5.4 KiB
Video System Refactoring Summary
Overview
تغییرات اساسی در معماری سیستم ویدیو برای اصلاح ساختار Collection و Playlist
Changes Made
1. Model Changes
❌ Removed:
- VideoInCollection model (مدل منسوخ شده که ویدیوها را مستقیماً به Collection ها متصل میکرد)
- videos field from VideoCollection (فیلد ManyToMany که ویدیوها را به Collection متصل میکرد)
✅ Kept:
- VideoPlaylistInCollection model (معماری صحیح که Playlist ها را به Collection متصل میکند)
- All other models: Video, VideoCategory, VideoCollection, VideoPlaylist, PlaylistItem
2. Architecture Improvement
قبل:
VideoCollection --[VideoInCollection]--> Video
بعد:
VideoCollection --[VideoPlaylistInCollection]--> VideoPlaylist --[PlaylistItem]--> Video
این تغییر باعث میشود:
- Collection ها شامل Playlist باشند (نه مستقیماً Video)
- سازماندهی بهتر محتوا
- معماری منطقیتر و قابل نگهداریتر
3. Admin Panel Updates
apps/video/admin.py:
- تغییر
VideoInCollectionInlineبهVideoPlaylistInCollectionInlineForCollection - تغییر
count_videos()بهcount_playlists()در Collection admin - حذف ارجاعات به VideoInCollection
4. Migration
Migration File: 0010_remove_videoincollection_model.py
- حذف فیلد videos از videocollection
- حذف مدل VideoInCollection
5. Management Commands
cleanup_video_data.py
حذف تمام دادههای VideoCategory، VideoCollection، و VideoPlaylist (بدون حذف Video)
Usage:
python manage.py cleanup_video_data --confirm
Deleted:
- 3 VideoCategories
- 4 VideoCollections
- 2 VideoPlaylists
- 3 PlaylistItems
create_video_playlists.py
ایجاد 10 پلیلیست با محتوای روسی درباره پیامبران و امامان
Usage:
python manage.py create_video_playlists
python manage.py create_video_playlists --dry-run # for testing
Created:
- 10 VideoPlaylists با عناوین و توضیحات روسی
- هر پلیلیست شامل تمام 31 ویدیو موجود
- محاسبه خودکار total_time برای هر پلیلیست
Playlists:
- Жизнь Пророка Мухаммада (да благословит его Аллах)
- Истории пророков в Коране
- Имам Али: Врата знаний
- Имам Хусейн и трагедия Кербелы
- Двенадцать Имамов Ахль аль-Байт
- Фатима аз-Захра: Дочь Пророка
- Имам Махди: Обещанный спаситель
- Пророки и их чудеса
- Учения Ахль аль-Байт о нравственности
- Имам Риза и его наследие
6. API Impact
Serializers: No changes needed - already using correct related_playlists relationship
Views: No changes needed - filtering and querying work correctly with new structure
Database State After Changes
Videos
- 31 videos (unchanged)
- No data loss
Playlists
- 10 new playlists
- Each contains all 31 videos
- Total duration per playlist: 1 day, 22:33:23
Collections
- 0 collections (deleted and ready for new structure)
- Can now only contain playlists (not direct videos)
Categories
- 0 categories (deleted and ready for new data)
Next Steps
- ✅ Migration applied successfully
- ✅ Old data cleaned up
- ✅ New playlists created
- 🔄 Create new VideoCollections and add playlists to them (if needed)
- 🔄 Create new VideoCategories and assign to playlists (if needed)
- 🔄 Test all API endpoints
Commands for Setup (in order)
# 1. Apply migration (already done)
python manage.py migrate video
# 2. Clean up old data (if needed)
python manage.py cleanup_video_data --confirm
# 3. Create 8 video categories
python manage.py create_video_categories
# 4. Create 10 playlists with all videos (automatically connects to categories)
python manage.py create_video_playlists
# 5. Check current state
python manage.py shell -c "
from apps.video.models import Video, VideoPlaylist, VideoCollection, VideoCategory
print(f'Videos: {Video.objects.count()}')
print(f'Categories: {VideoCategory.objects.count()}')
print(f'Playlists: {VideoPlaylist.objects.count()}')
print(f'Collections: {VideoCollection.objects.count()}')
"
Video Categories Created:
- Пророки и посланники (Prophets and Messengers)
- Имамы Ахль аль-Байт (Imams of Ahl al-Bayt)
- Коранические истории (Quranic Stories)
- Исламская философия (Islamic Philosophy)
- Нравственность и этика (Morality and Ethics)
- История ислама (History of Islam)
- Кербела и Ашура (Karbala and Ashura)
- Духовное развитие (Spiritual Development)
Important Notes
- ⚠️ VideoInCollection model is completely removed - old code referencing it will break
- ✅ Videos are preserved - no video data was lost
- ✅ New architecture is more logical: Collections → Playlists → Videos
- ✅ Admin panel updated to reflect new structure
- ✅ API endpoints still work with no changes needed