Hey friends! In this video of Django series I tried to teach you how to work with Models to manage our database tables and columns. At the end of this course, you will be able to build your own full-functioned website. But first, you should have knowledge about some technologies such as Python, Html, Css, Javascript, Flask and cmd. I hope it will be useful for you. Enjoy!
~ MySql Configuration
1. pip install mysqlclient
2. open your django project settings and change 'Databases' section like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'database name that you created for your project',
'USER': 'user name',
'PASSWORD': 'user password',
'HOST': 'localhost by default',
'PORT': '3306 by default',
}
}
3. save your changes and that's it :)
~ Notes for Django Models
NB do not forget to import models from django.db
1. create class and give it the name of the table you wanna create (Task, Article, Post, etc.)
2. inherit from models.Model that you imported
3. start writing your columns as you wish (Title, Content, Date, Author, Completed, etc.)
4. you have to select right fields to use for your columns (CharField for title, TextField for content, DateTimeField for date, BooleanField for completed, etc.)
5. finally, you should give a name for your model to recognize it afterwards (self.title, self.content, self.date_created, self.id, etc.)
6. result:
from django.db import models
class Task(models.Model):
title = models.CharField(max_length=30)
content = models.TextField()
date_created = models.DateTimeField(auto_now_add=True)
completed = models.BooleanField(default=False)
def __str__(self):
return str(self.title)
Friends, make sure to read about field and other features of models which I did not mentioned in video.
На этой странице сайта вы можете посмотреть видео онлайн Django Tutorial #5 | Models & Database migrations длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь codelikeyagami 01 Январь 1970, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 165 раз и оно понравилось 15 зрителям. Приятного просмотра!