Entrance Announcement
MICTE
2080
2080 Magh 07
Please contact us
Editing
User:Niraj/Teaching-25
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
'''Teaching lesson plan 25 Subject: Python programming''' '''Date: 12 Feb 2024''' '''Time: 60 minutes''' '''Period: 3rd''' '''Teaching Item: Introduction to Django Models''' '''Class: Bachelor''' '''Objective:''' Students will learn the fundamentals of Django models, including defining models, creating database tables, performing CRUD operations, and understanding relationships between models. '''Materials Needed:''' * Python installed (preferably Python 3.x) * Text editor or integrated development environment (IDE) such as VSCode, PyCharm, or Sublime Text * Django framework installed (<code>pip install django</code>) * Projector '''1. Introduction to Django Models (15 mins)''' * Overview of Django models: ** Django models represent database tables and their relationships. ** Models are defined using Python classes that inherit from <code>django.db.models.Model</code>. * Discuss the importance of models in Django projects and their role in data persistence. '''2. Defining Models (20 mins)''' * Creating a Django app for models: <code>python manage.py startapp myapp</code> * Defining model classes: ** Define model fields to represent database columns. ** Specify field types (e.g., CharField, IntegerField, ForeignKey). ** Add meta options such as <code>verbose_name</code> and <code>verbose_name_plural</code>. * Example: Creating a <code>Book</code> model with fields like <code>title</code>, <code>author</code>, <code>published_date</code>, etc. '''3. Migrations and Database Schema (20 mins)''' * Generating migrations: <code>python manage.py makemigrations</code> * Applying migrations to create database tables: <code>python manage.py migrate</code> * Understanding migration files and their role in database schema evolution. * Discussing how Django manages database schema changes over time. '''4. Performing CRUD Operations (25 mins)''' * Creating records: ** Using model classes to create new records. ** Saving records to the database using the <code>save()</code> method. * Retrieving records: ** Querying records using the model's <code>objects</code> manager. ** Filtering records based on specific criteria using <code>filter()</code>, <code>get()</code>, and <code>exclude()</code>. * Updating records: ** Retrieving records, modifying their attributes, and saving them back to the database. * Deleting records: ** Deleting records using the <code>delete()</code> method or bulk delete operations. '''5. Model Relationships (25 mins)''' * One-to-Many (ForeignKey) relationship: ** Defining relationships between models using ForeignKey fields. ** Understanding the concept of related objects and reverse relationships. * Many-to-Many relationship: ** Defining many-to-many relationships using ManyToManyField. ** Accessing related objects using querysets and reverse relationships. * One-to-One relationship: ** Defining one-to-one relationships using OneToOneField. ** Use cases and examples of one-to-one relationships. '''6. Exercise: Create and Manipulate Models (20 mins)''' * Provide a hands-on exercise where students create Django models and perform CRUD operations. * Task: ** Define multiple models representing real-world entities (e.g., Book, Author, Publisher). ** Create relationships between models (e.g., Book has an Author). ** Write Python code to create, retrieve, update, and delete records using Django models. '''7. Conclusion (10 mins)''' * Recap the key points covered in the lesson: ** Django models represent database tables and define the structure of data. ** Migrations are used to manage changes to the database schema over time. ** CRUD operations (Create, Retrieve, Update, Delete) can be performed using Django model objects. ** Relationships between models enable complex data modeling and querying. * Encourage students to practice creating models and performing CRUD operations in their Django projects.
Summary:
Please note that all contributions to ICTED-WIKI may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
ICTED-WIKI:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
User page
Discussion
English
Views
Read
Edit
Edit source
View history
More
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
User contributions
Logs
View user groups
Special pages
Page information