Académique Documents
Professionnel Documents
Culture Documents
order_by() Sorts the data by a given Products.objects.all().order_by(‘Name’). Select * from Products order by Name
column or a list of asc()
columns
Or
Or
Products.objects.all().order_by(‘Name’).
Select * from Products order by Name
asc()
desc
exclude() Filter by objects that Products.objects.all().exclude(name=’No Select * from Products where not
don’t match the given kia’) name=’Nokia’
lookup parameters
count() Returns the count of Products.objects.filter(name=’ Select count(*) from Products where
objects Hp’).count() name=’Hp’
DJANGO MODEL FUNCTIONS
contains/icont Field contains search Products.objects.filter(name__c Select * from products where name
ains text. icontains is ontains=’Hp’) like ‘Hp’
case-insensitive
version
in Returns rows that Products.objects.filter(name__i Select * from products where name
matches a list n=[‘nokia’,’samsung’,’hp’]) in(‘nokia’,’samsung’,’hp’)
Q operator:
Is used when the query is more comples.if you want to use OR operator in queries filter alone doesnt
work. You can use Q operator to implement this functionality,
Products.objects.get(Q(name__startswith=’N’) | Q(name__startswith=’H’))