Ceci est une ancienne révision du document !
Dans le module models.py d'une application :
from django.db import models class Author(models.Model): name = models.CharField(max_length=100, unique=True) class Book(models.Model): title = models.CharField(max_length=200) quantity = models.IntegerField(default = 1) author = models.ForeignKey(Author, on_delete=models.DO_NOTHING)
Paramètres :
blank | |
default | |
max_length | |
null | |
primary_key | True/False |
unique | True/False |
… |
Types :
BooleanField | |
CharField | |
DateField | |
DateTimeField | |
EmailField | |
FloatField | |
ForeignKey | Clé étrangère : Jointure vers un autre modèle |
IntegerField | |
… |
Valeurs pour on_delete :
models.CASCADE | |
models.DO_NOTHING | |
… |
Créer les migrations :
python manage.py makemigrations [nom_application]
Appliquer les migrations :
python manage.py migrate