Django Tutorial #5 | Models & Database migrations

Publicado em: 01 Janeiro 1970
no canal de: codelikeyagami
165
15

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.


Nesta página do site você pode assistir ao vídeo on-line Django Tutorial #5 | Models & Database migrations duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário codelikeyagami 01 Janeiro 1970, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 165 vezes e gostou 15 espectadores. Boa visualização!