Django Models Beginner Friendly Guide | Python Web Development
In this video we explain and simplify Django models which are a major foundation for any project created with Django. We start out by explaining what Django models are and how to create and manage a database when using Django, then we will create our own model, learn about different fields, meta data options, how to define the string method and how to create a one to many relationship between your model and a different Django model in this case we created a many to one relationship between our blog post model and the default user model. We also learn about how to access our data in Django admin. ⏱️ Chapters: 00:00 - Introduction 00:28 - What are Django models and why should we create them? 01:31 - Creating a Simple Django Model by Subclassing models.Model 01:55 - Model Fields Explained 02:19 - Understanding Django's CharField (Character Field) 02:45 - Overview of Django's TextField (Text Area) 03:02 - How Django Names Database Tables 03:32 - Changing Database Table Names with class Meta 04:10 - Running makemigrations 04:28 - The Initial Migration File in the Migrations Directory 05:15 - The ID Field / Primary Key Field 05:41 - Running the migrate Command 05:59 - Creating a Superuser to Access Django Admin 07:17 - Logging into Django's Administration Interface 07:34 - Registering Models in the Admin Interface 08:56 - Customizing Blog Name | Adding verbose_name 09:52 - Changing Model's Plural Name (verbose_name_plural) 11:14 - How Django Names Blog Objects 11:34 - Defining the String Method (__str__) 12:21 - Using DateTimeField in Models 12:28 - Adding a created_at Field and Setting auto_now_add to True 13:03 - Creating an updated_at Field to Automatically Track Record Updates 13:38 - Making a Second Migration - Handling Migration Conflicts 14:31 - Providing a One-Off Default Value to Existing Rows 15:20 - Examining the Second Migration File 16:26 - Subclassing admin.ModelAdmin to Show created_at Field in List Display 17:46 - Setting Ordering According to Creation Date by Overriding class Meta 18:35 - How to Show Older Posts First? 19:23 - Allowing Fields to be Blank (blank=True) 20:04 - Adding an Author Field (Many-to-One Relationship with Default User Model) 21:25 - ForeignKey on Delete Attribute Explained 21:51 - Making Migrations for the First Time and Encountering a Second Conflict (Adding a Non-Nullable Field) 22:34 - Defining a Default User Value in models.py (User's ID) 22:48 - Adding Author to Admin's List Display 📖 For more information, check out the official Django documentation: https://docs.djangoproject.com/en/5.0/topics/db/models/ ----- If you're considering hosting your app on DigitalOcean, it’d be awesome if you used my referral link! You'll get $200 in free credits, and I'll get $25. Here is the link: https://m.do.co/c/58e570dc13ea #django #python #backend #webdev #codingtutorial
Download
1 formatsVideo Formats
Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.