1
0

migrate_to_django5.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python3
  2. """
  3. Script de migration Django 3.2 → 5.1
  4. Corrige automatiquement les problèmes de compatibilité
  5. """
  6. import os
  7. import sys
  8. from pathlib import Path
  9. def fix_models_file(file_path):
  10. """Supprime les méthodes __unicode__ dépréciées"""
  11. print(f"🔧 Correction de {file_path}...")
  12. with open(file_path, 'r', encoding='utf-8') as f:
  13. content = f.read()
  14. # Supprimer les méthodes __unicode__
  15. lines = content.split('\n')
  16. new_lines = []
  17. skip_next = False
  18. for i, line in enumerate(lines):
  19. if 'def __unicode__(self):' in line:
  20. # Ignorer cette ligne et la suivante (return)
  21. skip_next = True
  22. continue
  23. if skip_next:
  24. skip_next = False
  25. continue
  26. new_lines.append(line)
  27. new_content = '\n'.join(new_lines)
  28. with open(file_path, 'w', encoding='utf-8') as f:
  29. f.write(new_content)
  30. print(f"✅ {file_path} corrigé")
  31. def main():
  32. base_dir = Path(__file__).resolve().parent
  33. print("🚀 Début de la migration Django 3.2 → 5.1")
  34. print("=" * 50)
  35. # Fichiers à corriger
  36. files_to_fix = [
  37. base_dir / 'blog' / 'models.py',
  38. base_dir / 'core' / 'models.py',
  39. ]
  40. print("\n📝 Correction des fichiers models.py...")
  41. for file_path in files_to_fix:
  42. if file_path.exists():
  43. fix_models_file(file_path)
  44. else:
  45. print(f"⚠️ {file_path} introuvable")
  46. print("\n" + "=" * 50)
  47. print("✅ Migration terminée !")
  48. print("\n📋 Prochaines étapes :")
  49. print("1. Activez votre environnement virtuel")
  50. print("2. Installez les dépendances : pip install -r requirements.txt")
  51. print("3. Générez une nouvelle SECRET_KEY et mettez à jour .env")
  52. print("4. Testez les migrations : python manage.py makemigrations")
  53. print("5. Appliquez les migrations : python manage.py migrate")
  54. print("6. Lancez le serveur : python manage.py runserver")
  55. if __name__ == '__main__':
  56. main()