Django 3 - Let's make To-Do-List / Database
We're modifying some settings inside of mysite directory(mysite -> settings.py)
Telling Django that we have another application that need to be set up inside of the project.
PUT 'main.apps.MainConfig' in installed_apps
The next thing we're going to do is to get into mysite directory, following this commend(into terminal)
"python manage.py migrate"
we'll see these ones...
"Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK "
Model: modeling information
main-> migrations -> model
we're going to create "ToDoList"
It essentially means we created database object, which is called ToDoList and define some of the attributes and entries that each model ToDoList is going to have.
whenever you create new attribute of the information over your model, class as variable and name the attribute ("name") and fill what to be stored in your database.
now we define another model, which is Item
Item is lil different because it's actually related to To-do-List, we're going to have items as a part of our to-do-list.
The reason we're doing this is because of CharField, which is a type of field that we could store the information, we actually don't know the type of field or Django doesn't know the type of field that To-do-List is . So we have to define the fact that we're going to use a foreign key in this case, a to-do list object when we create an item. On_delete is just saying if we delete to-do-list since all items exist on a to-do-list, we're going to have to delete all of these as well. That's what CASCADE does, which defining the fact that this has a special way of being removed.
Text will be the equal to a character field as well. text = models.CharField(max_length=300)
and creating Bolean field complete = models.BooleanField()
Followign Commend:
C:\Users\j\Desktop\pythonwork\Newproject>python manage.py makemigrations main
you're going to see this
Migrations for 'main':
main\migrations\0001_initial.py
- Create model ToDoList
- Create model Item
To apply this change; Following commend:
C:\Users\j\Desktop\pythonwork\Newproject>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, main, sessions
Running migrations:
Applying main.0001_initial... OK