-
Notifications
You must be signed in to change notification settings - Fork 0
Chapter 4 Models
models represent the database structure
Classes = db table class attribute = table column
Class.objects.all() = returns all publishers from the database
CreateObject = Class.objects.create() / This creates an object and saves directly to database in one command
CreateObject = Class() / Creates object but does not save
SaveObject = Class.objects.save() = This saves all changes to the Db by updating all columns in a row
UpdateObject = Class.objects.filter(id=52).update(name=" ") = This updates only one field
DeleteObject = Class.objects.get(" ").delete()
FilterDb = Class.objects.filter() = This returns a queryset. Useful for returning more than one
FilterDb = Class.objects.get() = returns single row from database
SortResults = Class.objects.order_by("attribute1",'att2')
RevResults = Class.objects.order_by('-attribute1')
You can also set a default order by adding a class Meta inside the database table class class Publisher(models.Model): class Meta: ordering = ['name']