django model.create code example

Example 1: 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 2: model object means in django

CREATE TABLE myapp_person (
    "id" serial NOT NULL PRIMARY KEY,
    "first_name" varchar(30) NOT NULL,
    "last_name" varchar(30) NOT NULL
);

Example 3: create django object

Author.objects.create(name="Joe")

Example 4: .save() in django

>>> one_entry = Entry.objects.get(pk=1)