django models tutorial code example
Example 1: create models in django
from django.db import models
class Contact(models.Model):
name = models.CharField(max_length=50)
email = models.CharField(max_length=50)
contact = models.CharField(max_length=50)
content = models.TextField()
def __str__(self):
return self.name + ' ' + self.email
Example 2: django model example
from django.db import models
class myModel(models.Model):
input1 = models.CharField(max_length=100)
input2 = models.TextField()
input3 - models.DateTimeField(auto_now=True)
def __str__(self):
return self.input1
Example 3: django models
Models in Django are classes that represent data base tables.
Example 4: django creating database
In your virtual environment, where your Django project lives,
use the following commands:
>> python3 manage.py makemigrations
>> python3 manage.py migrate
>> python3 manage.py sqlmigrate "name_app" "code_of_specific_object"
>> python3 manage.py shell