#Import the models
from .models import Model Name
#all() Retrieves all objects from table
queryset = Model Name. objects.all()
#get(attribute='value') Retrieve a single object based on matched attribute
queryItem = ModelName.objects.get(attribute='value' )
#filter(attribute='value') - Returns all items from table that match a particular attribute value
queryset = ModelName.object.filter(attribute='value')
queryset = ModelName.object.filter(attribute__.startswith='value')
queryset = ModelName.object.filter(attribute__endswith='value') #endswith is case sensitive
queryset = ModelName.object.filter(attribute__contains='value') #contains is case sensitive
queryset = ModelName.object.filter(attribute__icontains='value') #icontains is case insensitive
queryset = ModelName.object.filter(attribute__iexact='value') #iexact is case insensitive
queryset = ModelName.object.filter(attribute__exact='value') #exact is case sensitive
queryset = ModelName.object.filter(attribute__in=['value1', 'value2']) #in is case sensitive
queryset = ModelName.object.filter(attribute__gt='value') #gt is greater than
queryset = ModelName.object.filter(attribute__gte='value') #gte is greater than or equal to
queryset = ModelName.object.filter(attribute__lt='value') #lt is less than
queryset = ModelName.object.filter(attribute__lte='value') #lte is less than or equal to
queryset = ModelName.object.filter(attribute__range=['value1', 'value2']) #range is between two values
queryset = ModelName.object.filter(attribute__isnull=True) #isnull is true or false
queryset = ModelName.object.filter(attribute__isnull=False) #isnull is true or false
queryset = ModelName.object.filter(attribute__year='value') #year is a date field
queryset = ModelName.object.filter(attribute__month='value') #month is a date field
queryset = ModelName.object.filter(attribute__day='value') #day is a date field
queryset = ModelName.object.filter(attribute__week='value') #week is a date field
queryset = ModelName.object.filter(attribute__week_day='value') #week_day is a date field
queryset = ModelName.object.filter(attribute__hour='value') #hour is a date field
queryset = ModelName.object.filter(attribute__minute='value') #minute is a date field
queryset = ModelName.object.filter(attribute__second='value') #second is a date field
queryset = ModelName.object.filter(attribute__date='value') #date is a date field
queryset = ModelName.object.filter(attribute__time='value') #time is a date field
queryset = ModelName.object.filter(attribute__regex='value') #regex is a regular expression
queryset = ModelName.object.filter(attribute__iregex='value') #iregex is a case insensitive regular expression
#exclude(attribute='value') - Returns all items from table that do not match a particular attribute value
queryset = ModelName.object.exclude(attribute='value')
#order_by(attribute) - Returns all items from table in ascending order based on attribute
queryset = ModelName.filter(attribute='value').order_by('attribute')
#order_by(-attribute) - Returns all items from table in descending order based on attribute
queryset = ModelName.filter(attribute='value').order_by('-attribute')
#create(attribute='value') - Creates a new object in the table
newItem = ModelName.objects.create(attribute='value')
#save() - Saves a new object to the table
item = ModelName.objects.get(attribute='value')
item.attribute = 'new value'
item.save()
#delete() - Deletes an object from the table
item = ModelName.objects.last()
item.delete()
#Query the child objects of a model
item = ModelName.object.first()
item.childmodel_set.all()
More information can be found at the official Django Making Queries documentation.