leo-y
2/28/2018 - 5:39 AM

django shell

shell

python manage.py shell 
from todolist2.models import *


% python manage.py shell

>>> from sample.models import *

>>> s1 = Student(andrew_id='potus', fname='Donald', …)

>>> s1.save()

>>> c1 = Course(name='webapp', number='15637')

>>> c1.save()

>>> c1.students.add(s1)

>>> c1.save()

>>> c1.students.all()

>>> s1.course_set.all()

– Queries that span the relationship

• E.g., Course.objects.filter(students__fname__contains='e')

– Modifications to the other model objects

• Student s: s.course_set.all()