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

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:

  1. Жизнь Пророка Мухаммада (да благословит его Аллах)
  2. Истории пророков в Коране
  3. Имам Али: Врата знаний
  4. Имам Хусейн и трагедия Кербелы
  5. Двенадцать Имамов Ахль аль-Байт
  6. Фатима аз-Захра: Дочь Пророка
  7. Имам Махди: Обещанный спаситель
  8. Пророки и их чудеса
  9. Учения Ахль аль-Байт о нравственности
  10. Имам Риза и его наследие

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

  1. Migration applied successfully
  2. Old data cleaned up
  3. New playlists created
  4. 🔄 Create new VideoCollections and add playlists to them (if needed)
  5. 🔄 Create new VideoCategories and assign to playlists (if needed)
  6. 🔄 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:

  1. Пророки и посланники (Prophets and Messengers)
  2. Имамы Ахль аль-Байт (Imams of Ahl al-Bayt)
  3. Коранические истории (Quranic Stories)
  4. Исламская философия (Islamic Philosophy)
  5. Нравственность и этика (Morality and Ethics)
  6. История ислама (History of Islam)
  7. Кербела и Ашура (Karbala and Ashura)
  8. Духовное развитие (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