Skip to content

Instantly share code, notes, and snippets.

View egitimplus's full-sized avatar
😀

jure egitimplus

😀
View GitHub Profile
@egitimplus
egitimplus / bulk.py
Created October 29, 2019 12:43
toplu işlemler
# 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.
@egitimplus
egitimplus / filter.py
Created October 29, 2019 12:44
filter()
# 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ı')
@egitimplus
egitimplus / exclude.py
Created October 29, 2019 12:44
Exclude
# 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ı')
@egitimplus
egitimplus / exact.py
Created October 29, 2019 12:45
Exact
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
@egitimplus
egitimplus / lt_gt.py
Created October 29, 2019 12:46
lt & gt
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)
@egitimplus
egitimplus / startswith.py
Created October 29, 2019 12:47
Startswith, Endswith, Contains
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
@egitimplus
egitimplus / range
Created October 29, 2019 12:47
Range
start = 2
end = 5
User.objects.filter(id__range=(start, end))
User.objects.filter(id__in=[1, 3, 4])
@egitimplus
egitimplus / isnull.py
Created October 29, 2019 12:48
Isnull
# WHERE email IS NULL;
User.objects.filter(email__isnull=True)
@egitimplus
egitimplus / regex
Created October 29, 2019 12:49
Regex
User.objects.get(username__regex= r'^[a-zA-Z]+$')