django model create code example
Example 1: django create app
python manage.py startapp
Example 2: django objects.create()
SomeModel.objects.create(firstname='ricky', lastname='ticky')
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: str django
def __str__(self):
return self.name
Example 5: django models
Models in Django are classes that represent data base tables.
Example 6: super in django manager
class DahlBookManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(author='Roald Dahl')
class Book(models.Model):
title = models.CharField(max_length=100)
author = models.CharField(max_length=50)
objects = models.Manager()
dahl_objects = DahlBookManager()