This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in_bulk() methodu ile veritabanındaki kayıtları primary key veya benzersiz alan ile | |
# eşleştirerek çekebiliriz. dict olarak döner. | |
# User tablosundaki tüm kayıtları getirir. | |
User.objects.in_bulk() | |
User tablosundaki primary keyi 1 ve 2 olan kayıtlar | |
User.objects.in_bulk([1,2]) | |
# Blog tablosunda slug alanı filtered_word olan kayıtları getirir. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# WHERE active=1 | |
Products.objects.filter(active=True) | |
# WHERE active=1 AND name='Ürün Adı' | |
Products.objects.filter(active=True, name='Ürün Adı') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# WHERE NOT (active = 1 AND name ='Ürün Adı') | |
Products.objects.exclude(active=True, name='Ürün Adı') | |
# Exclude ve filter zincirleme olarak kullanılabilir. | |
# WHERE NOT active != 1 AND NOT name !='Ürün Adı' | |
Products.objects.exclude(active=True).exclude(name='Ürün Adı') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User.objects.get(username__exact = 'emre') # where username=emre | |
User.objects.get(username__exact =None) # where username is null | |
User.objects.get(username__iexact = 'emre') # EmRe emre |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User.objects.filter(is_staf__lt = 1) | |
User.objects.filter(is_staf__lte = 1) | |
User.objects.filter(is_staf__gt = 1) | |
User.objects.filter(is_staf__gte = 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User.objects.filter(username__startswith = 'e') #sadece e | |
User.objects.filter(username__startswith = 'e') # e ve E | |
User.objects.filter(username__endsswith = 'e') # sadece e | |
User.objects.filter(username__iendsswith = 'e') # e ve E | |
User.objects.filter(username__contains = 'e') # sadece e |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start = 2 | |
end = 5 | |
User.objects.filter(id__range=(start, end)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User.objects.filter(id__in=[1, 3, 4]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# WHERE email IS NULL; | |
User.objects.filter(email__isnull=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User.objects.get(username__regex= r'^[a-zA-Z]+$') |