-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDJ-02-Model-Single.txt
53 lines (36 loc) · 1.43 KB
/
DJ-02-Model-Single.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Django for Everybody - Single Table Models
https://www.dj4e.com/lectures/DJ-02-Model-Single.txt
You can check out the Django code for this project at:
https://github.com/csev/dj4e-samples
Start the command line in a Linux/Bash shell and go into your project folder.
Activate a virtual environment if needed.
cd dj4e-samples
git pull # incase there are updates
pip3 install -r requirements.txt # to make sure that all the utilities are there
python3 manage.py check # Make sure things are set up
python3 manage.py makemigrations # Probably won't find any changes
rm db.sqlite3 # In case you have done this before
python3 manage.py migrate # Create the database and table(s)
Start the django shell:
python3 manage.py shell
(In the shell at the prompt)
from users.models import User
u = User(name='Kristen', email='kf@umich.edu')
u.save()
u = User(name='Chuck', email='csev@umich.edu')
u.save()
u = User(name='Colleen', email='cvl@umich.edu')
u.save()
u = User(name='Ted', email='ted@umich.edu')
u.save()
u = User(name='Sally', email='a2@umich.edu')
u.save()
User.objects.values()
User.objects.filter(email='csev@umich.edu').values()
User.objects.filter(email='ted@umich.edu').delete()
User.objects.values()
User.objects.filter(email='csev@umich.edu').update(name='Charles')
User.objects.values()
User.objects.values().order_by('email')
User.objects.values().order_by('-name')
quit()