0% found this document useful (0 votes)
475 views

Django Web Development Python Cheat Sheet

The following document is django web development cheat sheet. One can access this cheat sheet for rapid solution about django web development.

Uploaded by

Pardeep Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
475 views

Django Web Development Python Cheat Sheet

The following document is django web development cheat sheet. One can access this cheat sheet for rapid solution about django web development.

Uploaded by

Pardeep Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

#Django Cheat Sheet and Quick Reference

#Database Engines #Example Model


from django.db import models #Useful Links
django.db.backends.postgresql
from django.utils import timezone
Django Website - https://www.djangoproject.com
django.db.backends.mysql
class Make(models.Model): Pretty Printed Website - http://prettyprinted.com
django.db.backends.sqlite3
name = models.CharField(max_length=15)
Pretty Pretty YouTube Channel -
django.db.backends.oracle factory_address = models.TextField() https://www.youtube.com/c/prettyprintedtutorials

#Example configuration in settings.py email = models.EmailField()

DATABASES = { def __str__(self):


'default': { return self.name

'ENGINE': 'django.db.backends.mysql',
class Car(models.Model):
'NAME': 'databasename', name = models.CharField(max_length=20)
active = BooleanField()
'USER': 'username',
date_added = DateTimeField(default=timezone.now)
'PASSWORD': 'password', price = FloatField()
make = models.ForeignKey(Make)
'HOST': '127.0.0.1',

'PORT': '5432', def __str__(self):

} return self.name

}
#Create Objects
#Model Fields
from .models import Make, Car
BooleanField
CharField toyota = Make(name='Toyota', factory_address='Somewhere in Japan...',
DateField email='[email protected]')
DateTimeField toyota.save()
DecimalField
EmailField camry = Car(name='Camry', active=True, price=29999.99, make=toyota)
FileField
camry.save()
FloatField
ImageField
IntegerField m
#Example Queries . co
TextField
d
nte
i
pr
Car.objects.get(pk=1) #get car with primary key = 1
Make.objects.all()
ty
#Relationship Fields Car.objects.filter(name='Camry') ret
Make.objects.all()[5:10] #offset 5, limit 10
://p
ForeignKey
Car.objects.order_by('name')
ttp
ManyToManyField Make.objects.filter(name__startswith='Toy') h
Car.objects.filter(make__name='Toyota') #relationship query

You might also like