Modifications entre les versions 1 et 6 (s'étendant sur 5 versions)
Version 1 à la date du 2013-08-29 16:16:07
Taille: 1660
Commentaire:
Version 6 à la date du 2013-08-29 16:41:44
Taille: 5738
Commentaire:
Texte supprimé. Texte ajouté.
Ligne 1: Ligne 1:
Chargement de l'environnement virtuel
=====================================
= Chargement de l'environnement virtuel =
Ligne 5: Ligne 5:
{{{ source atelier/bin/activtate }}}
Ligne 7: Ligne 6:
Création d'un projet Django
===========================
{{{
source atelier/bin/activtate
}}}
Ligne 10: Ligne 10:
Boostrap
--------
= Création d'un projet Django =


== Boostrap ==
Ligne 29: Ligne 31:
Base de données MySQL
---------------------
== Base de données MySQL ==
Ligne 37: Ligne 38:
  * {{{ python manage.py syncdb }}}(créer le superuser) {{{
python manage.py syncdb
}}}(créer le superuser)
Ligne 39: Ligne 42:
Activation de l'admin
---------------------
== Activation de l'admin ==
Ligne 57: Ligne 59:
Exploiter l'existant
====================
= Exploiter l'existant =

Création de l'application
{{{
django-admin.py startapp ancien
}}}

== Câblage db ==

  * dans 'foad/settings.py':
    * variable DATABASES, ajouter une nouvelle entrée au dictionnaire avec comme clef 'consultation-ancien'
    * variable INSTALLED_APPS, ajouter votre nouvelle application: 'ancien'

  * python manage.py inspectdb --database=consultation-ancien
  * python manage.py inspectdb --database=consultation-ancien > ancien/models.py
  * ouvrir le fichier ancien/models.py et ne garder que le modèle 'Atelier'
  * ajouter une méthode __unicode__() pour afficher l'intitulé quand on inspecte un objet
  X-( https://github.com/olarcheveque/atelier-south-inspectdb/blob/master/ancien/models.py

  * cabler le router de base de données (défini la politque d'accès aux bds)
    * X-( [[https://github.com/olarcheveque/atelier-south-inspectdb/blob/master/foad/db.py]]
    * X-( [[https://github.com/olarcheveque/atelier-south-inspectdb/blob/master/foad/settings.py#L30]]
  * python manage.py shell
   {{{
   from ancien.models import Atelier; Atelier.objects.all()
   }}}

== Câblage de l'ancien dans l'admin ==

  * création d'un fichier ancien/admin.py

  X-( [[ https://github.com/olarcheveque/atelier-south-inspectdb/blob/7b48f15e6ab64589bc39e24fcb2e00b5d5541cdd/ancien/admin.py ]]

= Nouveau système =

{{{
python manage.py startapp catalogue
}}}
  * dans 'foad/settings.py':
    * variable INSTALLED_APPS, ajouter votre nouvelle application: 'catalogue'

== initialisation du framework de migration pour l'app ==

{{{
python manage.py schemamigration catalogue --initial
python manage.py migrate catalogue
}}}

== Création du script de modification de BD selon le modèle ==

* création du modèle Formation dans catalogue/models.py

X-( [[https://github.com/olarcheveque/atelier-south-inspectdb/blob/6d153c1c3c4329720fe70a4dc5de6df5a91d41fd/catalogue/models.py ]]

{{{
python manage.py schemamigration catalogue --auto
python manage.py migrate catalogue
}}}

* création d'un fichier catalogue/admin.py
X-( [[ https://github.com/olarcheveque/atelier-south-inspectdb/blob/6d153c1c3c4329720fe70a4dc5de6df5a91d41fd/catalogue/admin.py ]]

== Itération 1 (création des formations à partir de l'existant) ==
{{{
python manage.py datamigration catalogue recuperation_id_intitule --freeze ancien
}}}

X-( [[https://github.com/olarcheveque/atelier-south-inspectdb/blob/6d153c1c3c4329720fe70a4dc5de6df5a91d41fd/catalogue/migrations/0003_recuperation_id_intitule.py#L9 ]]


== Itération 2 (création des universités à partir de l'existant) ==
* ajout du modèle Universite dans catalogue/models.py
{{{
python manage.py schemamigration catalogue --auto
python manage.py migrate catalogue
}}}
{{{
python manage.py datamigration catalogue creation_universite --freeze ancien
}}}
X-( [[https://github.com/olarcheveque/atelier-south-inspectdb/blob/cd81764142cce07ee2fb050e237a73f2815eb17c/catalogue/models.py]]
{{{
python manage.py migrate catalogue
}}}
X-( [[https://github.com/olarcheveque/atelier-south-inspectdb/blob/master/catalogue/migrations/0005_creation_universite.py#L9]]

== Itération 3 (création des domaines à partir de l'existant) ==
* ajout du modèle Universite dans catalogue/models.py
X-( [[https://github.com/olarcheveque/atelier-south-inspectdb/blob/master/catalogue/models.py#L20]]
{{{
python manage.py schemamigration catalogue --auto
python manage.py migrate catalogue
}}}

{{{
python manage.py datamigration catalogue creation_domaine --freeze ancien
}}}
X-( [[https://github.com/olarcheveque/atelier-south-inspectdb/blob/master/catalogue/migrations/0007_creation_domaine.py#L9]]
{{{
python manage.py migrate catalogue
}}}

= Commandes utiles =

En cas, d'une migration échouée, comme les modifications ne sont pas
transactionnelle, il est bon re resetter l'application dans un état stable,
corrélé avec les modèles.

{{{
python manage.py sqlclear catalogue > del_catalogue
mysql -u <user> -p --database=atelier < del_catalogue
python manage.py dbshell
  - delete from south_migrationhistory where app_name = 'catalogue';
}}}

Chargement de l'environnement virtuel

(Voir les prérequis de l'atelier)

source atelier/bin/activtate

Création d'un projet Django

Boostrap

python manage.py startproject foad
cd foad
python manage.py runserver (CTRL+C)
echo "*.pyc" > .gitignore
git init
git add .
git commit -m 'nouveau projet'

{OK} à chaque modification correcte au cours de l'atelier, commiter-les, vous pourrez plus facilement voir les modifications de fichiers, revenir en arrière, etc...

Base de données MySQL

python manage.py syncdb

(créer le superuser)

Activation de l'admin

Exploiter l'existant

Création de l'application

django-admin.py startapp ancien

Câblage db

Câblage de l'ancien dans l'admin

Nouveau système

python manage.py startapp catalogue
  • dans 'foad/settings.py':
    • variable INSTALLED_APPS, ajouter votre nouvelle application: 'catalogue'

initialisation du framework de migration pour l'app

python manage.py schemamigration catalogue --initial
python manage.py migrate catalogue

Création du script de modification de BD selon le modèle

* création du modèle Formation dans catalogue/models.py

X-( https://github.com/olarcheveque/atelier-south-inspectdb/blob/6d153c1c3c4329720fe70a4dc5de6df5a91d41fd/catalogue/models.py

python manage.py schemamigration catalogue --auto
python manage.py migrate catalogue

* création d'un fichier catalogue/admin.py X-( https://github.com/olarcheveque/atelier-south-inspectdb/blob/6d153c1c3c4329720fe70a4dc5de6df5a91d41fd/catalogue/admin.py

Itération 1 (création des formations à partir de l'existant)

python manage.py datamigration catalogue recuperation_id_intitule  --freeze ancien

X-( https://github.com/olarcheveque/atelier-south-inspectdb/blob/6d153c1c3c4329720fe70a4dc5de6df5a91d41fd/catalogue/migrations/0003_recuperation_id_intitule.py#L9

Itération 2 (création des universités à partir de l'existant)

* ajout du modèle Universite dans catalogue/models.py

python manage.py schemamigration catalogue --auto
python manage.py migrate catalogue

python manage.py datamigration catalogue creation_universite  --freeze ancien

X-( https://github.com/olarcheveque/atelier-south-inspectdb/blob/cd81764142cce07ee2fb050e237a73f2815eb17c/catalogue/models.py

python manage.py migrate catalogue

X-( https://github.com/olarcheveque/atelier-south-inspectdb/blob/master/catalogue/migrations/0005_creation_universite.py#L9

Itération 3 (création des domaines à partir de l'existant)

* ajout du modèle Universite dans catalogue/models.py X-( https://github.com/olarcheveque/atelier-south-inspectdb/blob/master/catalogue/models.py#L20

python manage.py schemamigration catalogue --auto
python manage.py migrate catalogue

python manage.py datamigration catalogue creation_domaine  --freeze ancien

X-( https://github.com/olarcheveque/atelier-south-inspectdb/blob/master/catalogue/migrations/0007_creation_domaine.py#L9

python manage.py migrate catalogue

Commandes utiles

En cas, d'une migration échouée, comme les modifications ne sont pas transactionnelle, il est bon re resetter l'application dans un état stable, corrélé avec les modèles.

python manage.py sqlclear catalogue > del_catalogue
mysql -u <user> -p --database=atelier < del_catalogue
python manage.py dbshell
  - delete from south_migrationhistory where app_name = 'catalogue';

Projet/SemaineTech/2013/Ateliers/DjangoInspectdbSouth/Support (dernière édition le 2013-09-06 13:09:42 par DavinBaragiotta)