django create model code example
Example 1: django create model from dictionary
m = MyModel(**data_dict)
m.save()
Example 2: 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 3: 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 4: django models
Models in Django are classes that represent data base tables.
Example 5: create django object
Author.objects.create(name="Joe")