model django code example

Example 1: create models in django

from django.db import models
# Create your models here.

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: primary key django model

class Garden(models.Model):
    garden_id = models.IntegerField(primary_key=True)

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: 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 5: django models

Models in Django are classes that represent data base tables.

Example 6: django id

The ID in django is a "unique identifier" for each models instances.
You do not need to explicitly add a ID field to your own models as 
the ID attribute is automatically generated for you behind the scences
by django for each new model and any newly created instances of that 
model afterwards.